summaryrefslogtreecommitdiffstats
path: root/ksquirrel/sq_navigatordropmenu.cpp
blob: c1a09a088befec803762e0643c926846b21f6133 (plain)
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
/***************************************************************************
                          sq_navigatordropmenu.cpp  -  description
                             -------------------
    begin                : ??? Feb 23 2005
    copyright            : (C) 2005 by Baryshev Dmitry
    email                : ksquirrel.iv@gmail.com
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <klocale.h>
#include <kaction.h>
#include <kio/job.h>
#include <kstringhandler.h>

#include "ksquirrel.h"
#include "sq_popupmenu.h"
#include "sq_navigatordropmenu.h"

SQ_NavigatorDropMenu * SQ_NavigatorDropMenu::m_instance= 0;

SQ_NavigatorDropMenu::SQ_NavigatorDropMenu(TQObject *tqparent) : TQObject(tqparent)
{
    m_instance = this;

    KActionCollection *ac = new KActionCollection(0, this, "Actions for drop menu");

    dropmenu = new SQ_PopupMenu(0);

    // "copy" action
    KAction *pACopy = new KAction(i18n("Copy here"), "editpaste", 0, this, TQT_SLOT(slotCopy()), ac, "sq_copy");

    // "move" action
    KAction *pAMove = new KAction(i18n("Move here"), 0, 0, this, TQT_SLOT(slotMove()), ac, "sq_move");

    // "link" action
    KAction *pALink = new KAction(i18n("Link here"), "www", 0, this, TQT_SLOT(slotLink()), ac, "sq_link");

    // "cancel" action, this action will do nothing - just close popup menu
    KAction *pACancel = new KAction(i18n("Cancel"), 0, 0, 0, 0, ac, "sq_cancel");

    // plug all actions to popup menu
    dropmenu->insertTitle(TQString());
    pACopy->plug(dropmenu);
    pAMove->plug(dropmenu);
    pALink->plug(dropmenu);
    dropmenu->insertSeparator();
    pACancel->plug(dropmenu);
}

SQ_NavigatorDropMenu::~SQ_NavigatorDropMenu()
{
    delete dropmenu;
}

void SQ_NavigatorDropMenu::slotCopy()
{
    if(also) emit done(url, SQ_NavigatorDropMenu::Copy);

    KIO::Job *job = KIO::copy(list, url);
    connect(job, TQT_SIGNAL(result(KIO::Job *)), this, TQT_SLOT(slotJobResult(KIO::Job *)));
}

void SQ_NavigatorDropMenu::slotMove()
{
    if(also) emit done(url, SQ_NavigatorDropMenu::Move);

    KIO::Job *job = KIO::move(list, url);
    connect(job, TQT_SIGNAL(result(KIO::Job *)), this, TQT_SLOT(slotJobResult(KIO::Job *)));
}

void SQ_NavigatorDropMenu::slotLink()
{
    if(also) emit done(url, SQ_NavigatorDropMenu::Link);

    KIO::Job *job = KIO::link(list, url);
    connect(job, TQT_SIGNAL(result(KIO::Job *)), this, TQT_SLOT(slotJobResult(KIO::Job *)));
}

void SQ_NavigatorDropMenu::slotJobResult(KIO::Job *job)
{
    if(job && job->error())
        job->showErrorDialog(KSquirrel::app());
}

/*
 *  Save destination url and urls of dropped files.
 */
void SQ_NavigatorDropMenu::setupFiles(const KURL::List &l, const KURL &u)
{
    list = l;
    url = u;

    dropmenu->changeTitle(KStringHandler::lsqueeze(u.isLocalFile() ? u.path() : u.prettyURL(), 20));
}

/*
 *  Show popup menu with available actions.
 */
void SQ_NavigatorDropMenu::exec(const TQPoint &pos, bool _also)
{
    also = _also;
    dropmenu->exec(pos);
}

#include "sq_navigatordropmenu.moc"