summaryrefslogtreecommitdiffstats
path: root/konq-plugins/kuick/kuick_plugin.cpp
blob: 27152e7b1c372c1940823acb028ef6ad51dba8c4 (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
/* This file is part of the KDE project
   Copyright (C) 2001 Holger Freyther <freyther@yahoo.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; version 2
   of the License.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#include "kuick_plugin.h"
#include "kuick_plugin.moc"
#include "kdirmenu.h"

#include <kapplication.h>
#include <kaction.h>
#include <kinstance.h>
#include <kiconloader.h>
#include <kimproxy.h>
#include <klocale.h>
#include <konq_popupmenu.h>
#include <kmessagebox.h>
#include <kgenericfactory.h>
#include <tqobject.h>
#include <kio/jobclasses.h>
#include <kio/job.h>
#include <kurl.h>

typedef KGenericFactory<KTestMenu, KonqPopupMenu> KTestMenuFactory;
K_EXPORT_COMPONENT_FACTORY( libkuickplugin, KTestMenuFactory("kuick_plugin") )

KTestMenu::KTestMenu( KonqPopupMenu *popupmenu, const char *name, const TQStringList& /*list*/ ) : KonqPopupMenuPlugin( popupmenu, name) {
    popup= popupmenu ;
    meta_copy_mmu = 0L;
    meta_move_mmu = 0L;
    my_action = new KAction( "kuick_plugin", 0, this, TQT_SLOT( slotPopupMaeh( ) ), actionCollection( ), "Do some funky stuff"  );
    tqaddAction( my_action );
    addSeparator();
    //popupmenu->addMerge();
    connect( popup, TQT_SIGNAL(aboutToShow() ), this, TQT_SLOT(slotPrepareMenu( ) ) );
    m_imProxy = KIMProxy::instance( kapp->dcopClient() );
}
KTestMenu::~KTestMenu( ){
     delete meta_copy_mmu;
     delete meta_move_mmu;
}
void KTestMenu::slotPopupMaeh( ){

}
void KTestMenu::slotStartCopyJob( const TQString &path ) {
     KURL url = KURL::fromPathOrURL( path );
     KIO::CopyJob *copy;
     copy = KIO::copy( popup->popupURLList(), url);
     copy->setAutoErrorHandlingEnabled( true );
}
void KTestMenu::slotStartMoveJob( const TQString &path) {
     KURL url = KURL::fromPathOrURL( path );
     KIO::CopyJob *move;
     move = KIO::move( popup->popupURLList(), url );
     move->setAutoErrorHandlingEnabled( true );
}

void KTestMenu::slotFileTransfer( const TQString &uid ) {
    m_imProxy->sendFile( uid, popup->popupURLList().first() );
}

void KTestMenu::slotPrepareMenu( ) { // now it's time to set up the menu...
// search for the dummy entry 'kuick_plugin' stores it index reomev it plug copy at the position
  KGlobal::locale()->insertCatalogue("kuick_plugin");

  bool isKDesktop = TQCString(  kapp->name() ) == "kdesktop";

  for(int i= popup->count(); i >=1; i--) {
    int id = popup->idAt( i );
    TQString text = popup->text( id );
    if( text.tqcontains("kuick_plugin") ) {
      popup->removeItem( id );
      if (isKDesktop && !kapp->authorize("editable_desktop_icons"))
      {
         // Remove seperator as well
         id = popup->idAt( i-1 );
         if (popup->text( id ).isEmpty())
            popup->removeItem( id );
         break;
      }
      meta_copy_mmu = new KMetaMenu(popup, popup->url(),
              i18n("&Copy Here") , "kuick-copy", m_imProxy );
      popup->insertItem(i18n("Copy To"), meta_copy_mmu, -1, i   );
      connect( meta_copy_mmu, TQT_SIGNAL(fileChosen(const TQString &) ), 
          TQT_SLOT(slotStartCopyJob(const TQString & )) );
      
      connect( meta_copy_mmu, TQT_SIGNAL( contactChosen( const TQString & ) ),
          TQT_SLOT( slotFileTransfer( const TQString & )) );
          
      if( popup->protocolInfo().supportsMoving() ){
        meta_move_mmu = new KMetaMenu(popup, popup->url(),
              i18n("&Move Here"), "kuick-move");
        popup->insertItem(i18n("Move To"), meta_move_mmu, -1, i+1 );
        connect( meta_move_mmu, TQT_SIGNAL(fileChosen(const TQString &) ), 
            TQT_SLOT(slotStartMoveJob(const TQString & )) );
      }
      break;
    }
  }
}