File: DragDrop.cpp

package info (click to toggle)
subcommander 2.0.0~b5p2-5
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 15,344 kB
  • sloc: cpp: 63,594; sh: 4,050; xml: 1,992; makefile: 1,134; ansic: 786; ruby: 251; lisp: 24
file content (123 lines) | stat: -rw-r--r-- 2,823 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* ====================================================================
 * Copyright (c) 2003-2007, Martin Hauner
 *                          http://subcommander.tigris.org
 *
 * Subcommander is licensed as described in the file doc/COPYING, which
 * you should have received as part of this distribution.
 * ====================================================================
 */

// sc
#include "config.h"
#include "DragDrop.h"
#include "util/apr.h"

// qt
#include <QtCore/QMimeData>

// svn
#include <svn_path.h>


QStringList decodeDropData( const QMimeData* data )
{
  QStringList result;

  if( data->hasFormat("text/uri-list") )
  {
    QByteArray bytes = data->data("text/uri-list");

    // extract all strings seperated by \r\n

    // cleanup %xx
    apr::Pool pool;
    const char* tmp  = svn_path_uri_decode(bytes.data(),pool);
    QString     drop = QString::fromUtf8(tmp);

    // cleanup path seperator
    drop.replace( "\\", "/" );

    for( int i = 0; true; i++ )
    {
      QString item = drop.section( "\r\n", i, i );

      if( item.isEmpty() )
      {
        break;
      }
      
      // MacOSX has a '/' at the end of an url, remove it.
      if( item.endsWith("/") && item.length() > 1 )
      {
        item = item.left(item.length()-1);
      }
      
      result.push_back(item);
    }
  }
  // windows: firefox
  else if( data->hasFormat("text/plain") )
  {
    QByteArray bytes = data->data("text/plain");

    // extract a single string until we hit a linefeed
    QString text(bytes);
    QString item = text.section( "\n", 0, 0 );
    result.push_back(item);
  }
  else
  {
    result.push_back( _q("unknown drag & drop format") );
  }

  return result;
}

QStringList decodeDropText( const QString& text, const QString& format )
{
  QStringList result;

  // windows: explorer/iexplore/totalcommander
  if( format == QString("text/uri-list") )
  {
    // extract all strings seperated by \r\n

    // cleanup %xx
    const char* tmp  = svn_path_uri_decode(text.toUtf8(),apr::Pool());
    QString     drop = QString::fromUtf8(tmp);

    // cleanup path seperator
    drop.replace( "\\", "/" );

    for( int i = 0; true; i++ )
    {
      QString item = drop.section( "\r\n", i, i );

      if( item.isEmpty() )
      {
        break;
      }
      
      // MacOSX has a '/' at the end of an url, remove it.
      if( item.endsWith("/") && item.length() > 1 )
      {
        item = item.left(item.length()-1);
      }
      
      result.push_back(item);
    }
  }
  // windows: firefox
  else if( format.contains("text/plain") == 1 )
  {
    // extract a single string until we hit a linefeed
    QString item = text.section( "\n", 0, 0 );
    result.push_back(item);
  }
  else
  {
    result.push_back( _q("unknown drag & drop format") );
  }

  return result;
}