~ubuntu-branches/ubuntu/trusty/krusader/trusty

« back to all changes in this revision

Viewing changes to krusader/Panel/panelfunc.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-08-08 13:47:36 UTC
  • mfrom: (1.2.19 upstream)
  • Revision ID: james.westby@ubuntu.com-20110808134736-8e630ivgd2c3sgg5
Tags: 1:2.4.0~beta1-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
#include <kdesktopfile.h>
60
60
#include <ktoggleaction.h>
61
61
#include <kurlcompletion.h>
 
62
#include <kmimetypetrader.h>
 
63
#include <kopenwithdialog.h>
 
64
#include <kshell.h>
62
65
 
63
66
#include "dirhistoryqueue.h"
64
67
#include "krcalcspacedialog.h"
113
116
    delete history;
114
117
}
115
118
 
116
 
//HACK used by panelmanager - remove this once per-tab save/restore is implemented
117
 
void ListPanelFunc::clearHistory()
118
 
{
119
 
    history->clear();
120
 
}
121
 
 
122
119
void ListPanelFunc::urlEntered(const QString &url)
123
120
{
124
121
    urlEntered(KUrl(
245
242
    if (!isEqualUrl) {
246
243
        panel->setCursor(Qt::WaitCursor);
247
244
        panel->view->op()->stopQuickFilter(false);
 
245
        panel->view->clearSavedSelection();
248
246
    }
249
247
 
250
248
    if(panel->vfsError)
306
304
 
307
305
        int savedHistoryState = history->state();
308
306
 
309
 
        if (vfsP->vfs_refresh(u))
 
307
        if (vfsP->vfs_refresh(u)) {
 
308
            // update the history, as the actual url might differ from the one requested
 
309
            history->setCurrentUrl(vfsP->vfs_getOrigin());
310
310
            break; // we have a valid refreshed URL now
 
311
        }
311
312
 
312
313
        refreshFailed = true;
313
314
 
318
319
        // prevent repeated error messages
319
320
        if (vfsP->vfs_isDeleting())
320
321
            break;
321
 
        if(!history->goBack())
322
 
            break;
 
322
        if(!history->goBack()) {
 
323
            // put the root dir to the beginning of history, if it's not there yet
 
324
            if (!u.equals(KUrl(ROOT_DIR), KUrl::CompareWithoutTrailingSlash))
 
325
                history->pushBack(KUrl(ROOT_DIR), QString());
 
326
            else
 
327
                break;
 
328
        }
323
329
        vfsP->vfs_setQuiet(true);
324
330
    }
325
331
    vfsP->vfs_setQuiet(false);
326
332
    panel->view->setNameToMakeCurrent(QString());
327
333
 
 
334
    panel->setCursor(Qt::ArrowCursor);
 
335
 
328
336
    // on local file system change the working directory
329
337
    if (files() ->vfs_getType() == vfs::VFS_NORMAL)
330
338
        QDir::setCurrent(KrServices::getPath(files()->vfs_getOrigin()));
495
503
    KTemporaryFile *tempFile = new KTemporaryFile;
496
504
    tempFile->open();
497
505
 
498
 
    KIO::CopyJob *job = KIO::move(tempFile->fileName(), fileToCreate);
 
506
    KIO::CopyJob *job = KIO::copy(tempFile->fileName(), fileToCreate);
499
507
    job->setUiDelegate(0);
 
508
    job->setDefaultPermissions(true);
500
509
    connect(job, SIGNAL(result(KJob*)), SLOT(slotFileCreated(KJob*)));
501
510
    connect(job, SIGNAL(result(KJob*)), tempFile, SLOT(deleteLater()));
502
511
}
549
558
        // ask the user for the copy dest
550
559
        virtualBaseURL = getVirtualBaseURL();
551
560
        dest = KChooseDir::getDir(s, dest, panel->virtualPath(), queue, preserveAttrs, virtualBaseURL);
552
 
        if (dest.isEmpty()) return ;   // the user canceled
 
561
        if (dest.isEmpty())
 
562
            return ;   // the user canceled
553
563
        if (preserveAttrs)
554
564
            pmode = PM_PRESERVE_ATTR;
555
565
        else
615
625
        // finally..
616
626
        otherFunc() ->files() ->vfs_addFiles(fileUrls, KIO::CopyJob::Move, files(), "", pmode);
617
627
    }
 
628
    if(KConfigGroup(krConfig, "Look&Feel").readEntry("UnselectBeforeOperation", _UnselectBeforeOperation)) {
 
629
        panel->view->saveSelection();
 
630
        panel->view->unselect(KRQuery("*"));
 
631
    }
618
632
}
619
633
 
620
634
// called from SLOTS to begin the renaming process
737
751
        // ask the user for the copy dest
738
752
        virtualBaseURL = getVirtualBaseURL();
739
753
        dest = KChooseDir::getDir(s, dest, panel->virtualPath(), queue, preserveAttrs, virtualBaseURL);
740
 
        if (dest.isEmpty()) return ;   // the user canceled
 
754
        if (dest.isEmpty())
 
755
            return ;   // the user canceled
741
756
        if (preserveAttrs)
742
757
            pmode = PM_PRESERVE_ATTR;
743
758
        else
793
808
        // finally..
794
809
        otherFunc() ->files() ->vfs_addFiles(fileUrls, KIO::CopyJob::Copy, 0, "", pmode);
795
810
    }
 
811
    if(KConfigGroup(krConfig, "Look&Feel").readEntry("UnselectBeforeOperation", _UnselectBeforeOperation)) {
 
812
        panel->view->saveSelection();
 
813
        panel->view->unselect(KRQuery("*"));
 
814
    }
796
815
}
797
816
 
798
817
void ListPanelFunc::deleteFiles(bool reallyDelete)
920
939
    }
921
940
}
922
941
 
 
942
void ListPanelFunc::runCommand(QString cmd)
 
943
{
 
944
    krOut<<cmd<<endl;
 
945
    QString workdir = panel->virtualPath().isLocalFile() ?
 
946
            panel->virtualPath().path() : QDir::homePath();
 
947
    if(!KRun::runCommand(cmd, krMainWindow, workdir))
 
948
        KMessageBox::error(0, i18n("Couldn't start %1", cmd));
 
949
}
 
950
 
 
951
void ListPanelFunc::runService(const KService &service, KUrl::List urls)
 
952
{
 
953
    krOut<<service.name()<<endl;
 
954
    QStringList args = KRun::processDesktopExec(service, urls);
 
955
    if (args.count())
 
956
        runCommand(KShell::joinArgs(args));
 
957
    else
 
958
        KMessageBox::error(0, i18n("%1 can't open %2", service.name(), urls.toStringList().join(", ")));
 
959
}
 
960
 
 
961
void ListPanelFunc::displayOpenWithDialog(KUrl::List urls)
 
962
{
 
963
    KOpenWithDialog dialog(urls, panel);
 
964
    dialog.hideRunInTerminal();
 
965
    if (dialog.exec()) {
 
966
        KService::Ptr service = dialog.service();
 
967
        if(!service)
 
968
            service = KService::Ptr(new KService(dialog.text(), dialog.text(), QString()));
 
969
        runService(*service, urls);
 
970
    }
 
971
}
 
972
 
923
973
// this is done when you double click on a file
924
974
void ListPanelFunc::execute(const QString& name)
925
975
{
928
978
        return ;
929
979
    }
930
980
 
 
981
    krOut<<name<<endl;
 
982
 
931
983
    vfile *vf = files() ->vfs_search(name);
932
984
    if (vf == 0)
933
985
        return ;
953
1005
        openUrl(path);
954
1006
    } else {
955
1007
        KUrl url = files() ->vfs_getFile(name);
956
 
        KFileItem kfi(vf->vfile_getEntry(), url, true);
957
 
        kfi.run();
 
1008
        if (KRun::isExecutableFile(url, vf->vfile_getMime()))
 
1009
            runCommand(url.path());
 
1010
        else {
 
1011
            KService::Ptr service = KMimeTypeTrader::self()->preferredService(vf->vfile_getMime());
 
1012
            if(service)
 
1013
                runService(*service, KUrl::List(url));
 
1014
            else
 
1015
                displayOpenWithDialog(KUrl::List(url));
 
1016
        }
958
1017
    }
959
1018
}
960
1019
 
1266
1325
    panel->_actions->actHome->setEnabled(!atHome());
1267
1326
    panel->_actions->actHistoryBackward->setEnabled(history->canGoBack());
1268
1327
    panel->_actions->actHistoryForward->setEnabled(history->canGoForward());
1269
 
    KrActions::actTogglePreviews->setChecked(panel->view->previewsShown());
1270
1328
    panel->view->op()->emitRefreshActions();
1271
1329
}
1272
1330
 
1370
1428
 
1371
1429
void ListPanelFunc::root()
1372
1430
{
1373
 
    openUrl(KUrl("/"));
 
1431
    openUrl(KUrl(ROOT_DIR));
1374
1432
}
1375
1433
 
1376
1434
void ListPanelFunc::syncOtherPanel()