~carlos-mazieri/ubuntu-filemanager-app/samba-ui-03

« back to all changes in this revision

Viewing changes to src/plugin/folderlistmodel/clipboard.cpp

  • Committer: Tarmac
  • Author(s): carlos-mazieri
  • Date: 2015-08-06 19:57:41 UTC
  • mfrom: (430.2.2 samba-actions-01)
  • Revision ID: tarmac-20150806195741-0vemyy0iahard37d
Clipboard now uses LocationURL class to know which URLs are supported by the file manager.
Added LocationURL::supportedURLs() LocationURL::isSupportedUrl()
New protocols added into File Manager does not require clipboard changes anymore.

Approved by Arto Jalkanen, Ubuntu Phone Apps Jenkins Bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
 */
36
36
 
37
37
#include "clipboard.h"
 
38
#include "locationurl.h"
38
39
 
39
40
#include <QClipboard>
40
41
#include <QApplication>
189
190
 */
190
191
DirModelMimeData::ClipBoardDataOwner
191
192
DirModelMimeData::setIntoClipboard(const QStringList &files, const QString& path, ClipboardOperation operation)
192
 
{
193
 
    static bool firstTime = true;
 
193
{   
194
194
    DirModelMimeData::ClipBoardDataOwner  ret = Nobody;
195
195
    QClipboard *clipboard = QApplication::clipboard();
196
196
    if (clipboard)
200
200
                                                  : new DirModelMimeData();
201
201
        if (mime->fillClipboard(files, path, operation))
202
202
        {
 
203
            static bool firstTime = true;
203
204
            clipboard->setMimeData(mime);
204
205
            //it looks like some mobile devices does not have X or Clipboard does work for other reason
205
206
            //in this case we simulate our own clipboard, the QClipboard::dataChanged() signal is also
254
255
    QStringList fullPaths = makeFullPath(files, path);
255
256
    for(int counter = 0; counter < fullPaths.count(); counter++)
256
257
    {
257
 
        QUrl item = QUrl::fromLocalFile(fullPaths.at((counter)));
258
 
        m_urls.append(item);
259
 
        m_gnomeData += QLatin1Char('\n') + item.toEncoded() ;
260
 
    }
261
 
    setData(GNOME_COPIED_MIME_TYPE, m_gnomeData);
262
 
    setUrls(m_urls);
263
 
 
264
 
    return true;
 
258
        QUrl item(fullPaths.at((counter)));
 
259
        if (item.scheme().isEmpty() && !item.isLocalFile())
 
260
        {
 
261
            item = QUrl::fromLocalFile(fullPaths.at((counter)));
 
262
        }
 
263
        if (LocationUrl::isSupportedUrl(item))
 
264
        {
 
265
            m_urls.append(item);
 
266
            m_gnomeData += QLatin1Char('\n') + item.toEncoded() ;
 
267
        }
 
268
    }
 
269
    bool ret = m_urls.count() > 0;
 
270
    if (ret)
 
271
    {
 
272
        setData(GNOME_COPIED_MIME_TYPE, m_gnomeData);
 
273
        setUrls(m_urls);
 
274
    }
 
275
    return ret;
265
276
}
266
277
 
267
278
//===============================================================================================
292
303
 
293
304
//===============================================================================================
294
305
/*!
295
 
 * \brief DirModelMimeData::localUrls
296
 
 * \return
 
306
 * \brief DirModelMimeData::storedUrls
 
307
 * \return the list of Urls stored in the Clipboard
297
308
 */
298
309
QStringList
299
 
DirModelMimeData::localUrls(ClipboardOperation& operation)
 
310
DirModelMimeData::storedUrls(ClipboardOperation& operation)
300
311
{
301
312
     m_appMime = clipboardMimeData();
302
313
     QStringList paths;
315
326
         }
316
327
         for (int counter=0; counter < urls.count(); counter++)
317
328
         {
318
 
             if (urls.at(counter).toString().startsWith(QLatin1String("file://")))
 
329
             if (LocationUrl::isSupportedUrl(urls.at(counter)))
319
330
             {
320
 
                 paths.append(urls.at(counter).toLocalFile());
 
331
                 if (urls.at(counter).isLocalFile())
 
332
                 {
 
333
                     paths.append(urls.at(counter).toLocalFile());
 
334
                 }
 
335
                 else
 
336
                 {
 
337
                     paths.append(urls.at(counter).toString());
 
338
                 }
321
339
             }
322
340
         }
323
341
     }
340
358
    bool ret = false;
341
359
    ClipboardOperation tmpOperation;
342
360
    QStringList expectedList = makeFullPath(files,path);
343
 
    QStringList realList     = localUrls(tmpOperation);
 
361
    QStringList realList     = storedUrls(tmpOperation);
344
362
    if (realList == expectedList)
345
363
    {
346
364
        ret = true;
354
372
 
355
373
//===============================================================================================
356
374
/*!
357
 
 * \brief DirModelMimeData::makeFullPath() Just creates a fulpath file list when they do exist
 
375
 * \brief DirModelMimeData::makeFullPath() Just creates a fulpath file list if files are relative
358
376
 * \param files
359
377
 * \param path
360
378
 * \return the list itself
362
380
QStringList DirModelMimeData::makeFullPath(const QStringList& files, const QString &path)
363
381
{
364
382
    QStringList fullPathnameList;
365
 
    QFileInfo fi;
366
 
    for(int counter = 0; counter < files.count(); counter++)
 
383
    if (files.count() > 0)
367
384
    {
368
 
        const QString& item = files.at(counter);
369
 
        fi.setFile(item);
370
 
        if (!fi.isAbsolute())
 
385
        if (path.length() > 0 && !files.at(0).startsWith(path))
371
386
        {
372
 
            fi.setFile(path + QDir::separator() + item);
 
387
            for(int counter = 0; counter < files.count(); counter++)
 
388
            {
 
389
                fullPathnameList.append(path + QDir::separator() + files.at(counter));
 
390
            }
373
391
        }
374
 
        if (fi.exists())
 
392
        else
375
393
        {
376
 
            fullPathnameList.append(fi.absoluteFilePath());
 
394
            //they already have a full path
 
395
            fullPathnameList = files;
377
396
        }
378
397
    }
379
398
    return fullPathnameList;
459
478
 
460
479
//=======================================================
461
480
/*!
462
 
 * \brief Clipboard::clipboardLocalUrlsCounter
 
481
 * \brief Clipboard::storedUrlsCounter
463
482
 * \return
464
483
 */
465
 
int Clipboard::clipboardLocalUrlsCounter()
 
484
int Clipboard::storedUrlsCounter()
466
485
{
467
486
    ClipboardOperation operation;
468
 
    return m_mimeData->localUrls(operation).count();
 
487
    return m_mimeData->storedUrls(operation).count();
469
488
}
470
489
 
471
490
 
477
496
 */
478
497
QStringList Clipboard::paste(ClipboardOperation &operation)
479
498
{
480
 
    QStringList items = m_mimeData->localUrls(operation);
 
499
    QStringList items = m_mimeData->storedUrls(operation);
481
500
    if (operation == ClipboardCut)
482
501
    {
483
502
        //this must still be false when cut finishes to change the clipboard to the target