~ubuntu-branches/ubuntu/utopic/smb4k/utopic-proposed

« back to all changes in this revision

Viewing changes to plugin/smb4k_konqplugin.cpp

  • Committer: Package Import Robot
  • Author(s): Fathi Boudra
  • Date: 2012-05-19 18:54:34 UTC
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: package-import@ubuntu.com-20120519185434-kpqpdrg5i47zm7tl
Tags: upstream-1.0.1
ImportĀ upstreamĀ versionĀ 1.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *   Copyright (C) 2004 by Massimo Callegari                               *
3
 
 *   massimocallegari@yahoo.it                                             *
4
 
 *                                                                         *
5
 
 *   This program is free software; you can redistribute it and/or modify  *
6
 
 *   it under the terms of the GNU General Public License as published by  *
7
 
 *   the Free Software Foundation; either version 2 of the License, or     *
8
 
 *   (at your option) any later version.                                   *
9
 
 *                                                                         *
10
 
 *   This program is distributed in the hope that it will be useful,       *
11
 
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12
 
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13
 
 *   GNU General Public License for more details.                          *
14
 
 *                                                                         *
15
 
 *   You should have received a copy of the GNU General Public License     *
16
 
 *   along with this program; if not, write to the                         *
17
 
 *   Free Software Foundation, Inc.,                                       *
18
 
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19
 
 ***************************************************************************/
20
 
 
21
 
// Qt includes
22
 
#include <qapplication.h>
23
 
#include <qlabel.h>
24
 
#include <qtooltip.h>
25
 
#include <qstring.h>
26
 
#include <qwidget.h>
27
 
#include <qlayout.h>
28
 
#include <qpainter.h>
29
 
#include <qheader.h>
30
 
#include <qvaluelist.h>
31
 
#include <qpixmap.h>
32
 
#include <qtoolbutton.h>
33
 
#include <qtoolbar.h>
34
 
#include <qdir.h>
35
 
#include <qpushbutton.h>
36
 
 
37
 
// KDE includes
38
 
#include <klibloader.h>
39
 
#include <kinstance.h>
40
 
#include <klocale.h>
41
 
#include <kiconloader.h>
42
 
#include <kmessagebox.h>
43
 
#include <kdialogbase.h>
44
 
#include <kcombobox.h>
45
 
#include <ktoolbarbutton.h>
46
 
#include <kaction.h>
47
 
#include <kactionclasses.h>
48
 
#include <kconfigdialog.h>
49
 
 
50
 
// plugin specific includes
51
 
// #include "smb4k_konqplugin.moc"
52
 
#include "smb4k_konqplugin.h"
53
 
#include "../smb4k/core/smb4kcore.h"
54
 
#include "../smb4k/core/smb4kdefs.h"
55
 
 
56
 
smb4kWidget::smb4kWidget( QWidget * parent, const char * name, WFlags f )
57
 
                 : QVBox(parent, name, f)
58
 
{
59
 
 // Nothing exciting to do !
60
 
}
61
 
 
62
 
KonqSidebar_Smb4K::KonqSidebar_Smb4K(KInstance *inst,QObject *parent,QWidget *widgetParent, QString &desktopName, const char* name):
63
 
                   KonqSidebarPlugin(inst,parent,widgetParent,desktopName,name)
64
 
{
65
 
 
66
 
  widget = new smb4kWidget( widgetParent );
67
 
 
68
 
  KToolBar  *topBar = new KToolBar( widget, "Topbar" );
69
 
  topBar->setIconSize(16);
70
 
  topBar->insertButton( "reload",    0, SIGNAL( clicked() ), this, SLOT( slotRescan() ) , TRUE, i18n( "Scan Network" ) );
71
 
  topBar->insertButton( "find",      1, SIGNAL( clicked() ), this, SLOT( slotSearch() ) , TRUE,  i18n( "Search" ) );
72
 
  topBar->insertButton( "configure", 2, SIGNAL( clicked() ), this, SLOT( slotSmb4KOptionsDlg() ) , TRUE,  i18n( "Configure" ) );
73
 
 
74
 
  //
75
 
  // Browser widget:
76
 
  //
77
 
  KLibFactory *browser_factory = KLibLoader::self()->factory( "libsmb4knetworkbrowser" );
78
 
 
79
 
  if ( browser_factory )
80
 
  {
81
 
    m_browser_part = static_cast<KParts::Part *>( browser_factory->create( widget, "BrowserPart", "KParts::Part", QStringList( "konqplugin=\"true\"" ) ) );
82
 
 
83
 
    // Do nothing here. The network scan (and the mounting of recently used
84
 
    // shares) will be done by Smb4KCore::init() below.
85
 
  }
86
 
  else
87
 
  {
88
 
    KMessageBox::error( 0, "<qt>"+KLibLoader::self()->lastErrorMessage()+"</qt>" );
89
 
 
90
 
    return;
91
 
  }
92
 
 
93
 
  connect( Smb4KCore::mounter(), SIGNAL( mountedShare( const QString &) ), this, SLOT( slotMountedShare( const QString & ) ) );
94
 
  connect( Smb4KCore::mounter(), SIGNAL( aboutToUnmount( const QString& ) ), this, SLOT( slotPrepareUnmount( const QString& ) ) );
95
 
 
96
 
  // Scan the network and remount recently used shares:
97
 
  Smb4KCore::self()->init();
98
 
 
99
 
}
100
 
 
101
 
 
102
 
KonqSidebar_Smb4K::~KonqSidebar_Smb4K()
103
 
{
104
 
 
105
 
}
106
 
 
107
 
extern "C"
108
 
{
109
 
    void* create_konqsidebar_smb4k(KInstance *instance,QObject *par,QWidget *widp,QString &desktopname,const char *name)
110
 
    {
111
 
     KGlobal::locale()->insertCatalogue("smb4k");
112
 
     return new KonqSidebar_Smb4K(instance,par,widp,desktopname,name);
113
 
    }
114
 
};
115
 
 
116
 
extern "C"
117
 
{
118
 
 bool add_konqsidebar_smb4k(QString* fn, QString* /*param*/, QMap<QString,QString> *map)
119
 
     {
120
 
      map->insert("Type","Link");
121
 
      map->insert("Icon","smb4k");
122
 
      map->insert("Name",i18n("Samba Browser"));
123
 
      map->insert("Open","false");
124
 
      map->insert("X-KDE-KonqSidebarModule","konqsidebar_smb4k");
125
 
      fn->setLatin1("smb4k%1.desktop");
126
 
      return true;
127
 
     }
128
 
}
129
 
 
130
 
void KonqSidebar_Smb4K::handleURL(const KURL &url)
131
 
{
132
 
 currentKonquerorURL = url.path();
133
 
 //kdDebug() << "KonqSidebar_Smb4K::handleURL - "<< currentKonquerorURL << endl;
134
 
}
135
 
 
136
 
void KonqSidebar_Smb4K::slotRescan()
137
 
{
138
 
  // Send a custom rescan event to the browser part.
139
 
  QApplication::postEvent( m_browser_part, new QCustomEvent( EVENT_SCAN_NETWORK ) );
140
 
}
141
 
 
142
 
void KonqSidebar_Smb4K::slotSearch()
143
 
{
144
 
  // Load the factory of the config dialog:
145
 
  KLibFactory *search_factory = KLibLoader::self()->factory( "libsmb4ksearchdialog" );
146
 
 
147
 
  if ( search_factory )
148
 
  {
149
 
    KDialogBase *searchDialog = new KDialogBase( KDialogBase::Plain, i18n( "Search Dialog" ), KDialogBase::Close,
150
 
                                              KDialogBase::NoDefault, widget, "sd", true, true );
151
 
 
152
 
    QFrame *frame = searchDialog->plainPage();
153
 
 
154
 
    m_search_part = static_cast<KParts::Part *>( search_factory->create( frame, "SearchDialogPart", "KParts::Part" ) );
155
 
 
156
 
    if ( m_search_part )
157
 
    {
158
 
      QGridLayout *layout = new QGridLayout( frame );
159
 
      layout->setSpacing( 10 );
160
 
      layout->setMargin( 0 );
161
 
      layout->addWidget ( m_search_part->widget(), 0, 0, 0 );
162
 
      searchDialog->resize(400,300);
163
 
      // We do not want the dialog to be closed if the user presses return.
164
 
      // Instead we want that a search is started:
165
 
      searchDialog->actionButton( KDialogBase::Close )->setAutoDefault( false );
166
 
 
167
 
      //connect( m_search_dialog, SIGNAL( searchResult( Smb4KHostItem * ) ), this, SLOT( slotInsertItem( Smb4KHostItem * ) ) );
168
 
 
169
 
      searchDialog->show();
170
 
    }
171
 
    else
172
 
    {
173
 
      delete searchDialog;
174
 
    }
175
 
  }
176
 
  else
177
 
  {
178
 
    KMessageBox::error( 0, "<qt>"+KLibLoader::self()->lastErrorMessage()+"</qt>" );
179
 
 
180
 
    return;
181
 
  }
182
 
}
183
 
 
184
 
void KonqSidebar_Smb4K::slotSmb4KOptionsDlg()
185
 
{
186
 
  // Load the factory of the config dialog:
187
 
  KLibFactory *config_factory = KLibLoader::self()->factory( "libsmb4kconfigdialog" );
188
 
 
189
 
  if ( config_factory )
190
 
  {
191
 
    KConfigDialog *dlg = static_cast<KConfigDialog *>( config_factory->create( widget, "ConfigDialog", "KConfigDialog" ) );
192
 
 
193
 
    if ( dlg )
194
 
    {
195
 
      connect( dlg,  SIGNAL( settingsChanged() ), this, SLOT( slotSettingsChanged() ) );
196
 
 
197
 
      dlg->show();
198
 
    }
199
 
  }
200
 
  else
201
 
  {
202
 
    KMessageBox::error( 0, "<qt>"+KLibLoader::self()->lastErrorMessage()+"</qt>" );
203
 
 
204
 
    return;
205
 
  }
206
 
 
207
 
}
208
 
 
209
 
void KonqSidebar_Smb4K::slotSettingsChanged()
210
 
{
211
 
  QApplication::postEvent( m_browser_part, new QCustomEvent( EVENT_LOAD_SETTINGS ) );
212
 
}
213
 
 
214
 
void KonqSidebar_Smb4K::slotMountedShare( const QString &mountedShare )
215
 
{
216
 
 emit openURLRequest( KURL(mountedShare) );
217
 
}
218
 
 
219
 
void KonqSidebar_Smb4K::slotPrepareUnmount( const QString &mountpoint )
220
 
{
221
 
  if ( QString::compare( currentKonquerorURL, mountpoint ) == 0 )
222
 
  {
223
 
    emit openURLRequest( KURL( QDir::home().canonicalPath() ) );
224
 
  }
225
 
  else
226
 
  {
227
 
    // Nothing to do
228
 
  }
229
 
}
230
 
 
231
 
#include "smb4k_konqplugin.moc"
232
 
 
233
 
 
234
 
 
235
 
 
236