1
/***************************************************************************
2
* Copyright (C) 2004 by Massimo Callegari *
3
* massimocallegari@yahoo.it *
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. *
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. *
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
***************************************************************************/
22
#include <qapplication.h>
30
#include <qvaluelist.h>
32
#include <qtoolbutton.h>
35
#include <qpushbutton.h>
38
#include <klibloader.h>
39
#include <kinstance.h>
41
#include <kiconloader.h>
42
#include <kmessagebox.h>
43
#include <kdialogbase.h>
44
#include <kcombobox.h>
45
#include <ktoolbarbutton.h>
47
#include <kactionclasses.h>
48
#include <kconfigdialog.h>
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"
56
smb4kWidget::smb4kWidget( QWidget * parent, const char * name, WFlags f )
57
: QVBox(parent, name, f)
59
// Nothing exciting to do !
62
KonqSidebar_Smb4K::KonqSidebar_Smb4K(KInstance *inst,QObject *parent,QWidget *widgetParent, QString &desktopName, const char* name):
63
KonqSidebarPlugin(inst,parent,widgetParent,desktopName,name)
66
widget = new smb4kWidget( widgetParent );
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" ) );
77
KLibFactory *browser_factory = KLibLoader::self()->factory( "libsmb4knetworkbrowser" );
79
if ( browser_factory )
81
m_browser_part = static_cast<KParts::Part *>( browser_factory->create( widget, "BrowserPart", "KParts::Part", QStringList( "konqplugin=\"true\"" ) ) );
83
// Do nothing here. The network scan (and the mounting of recently used
84
// shares) will be done by Smb4KCore::init() below.
88
KMessageBox::error( 0, "<qt>"+KLibLoader::self()->lastErrorMessage()+"</qt>" );
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& ) ) );
96
// Scan the network and remount recently used shares:
97
Smb4KCore::self()->init();
102
KonqSidebar_Smb4K::~KonqSidebar_Smb4K()
109
void* create_konqsidebar_smb4k(KInstance *instance,QObject *par,QWidget *widp,QString &desktopname,const char *name)
111
KGlobal::locale()->insertCatalogue("smb4k");
112
return new KonqSidebar_Smb4K(instance,par,widp,desktopname,name);
118
bool add_konqsidebar_smb4k(QString* fn, QString* /*param*/, QMap<QString,QString> *map)
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");
130
void KonqSidebar_Smb4K::handleURL(const KURL &url)
132
currentKonquerorURL = url.path();
133
//kdDebug() << "KonqSidebar_Smb4K::handleURL - "<< currentKonquerorURL << endl;
136
void KonqSidebar_Smb4K::slotRescan()
138
// Send a custom rescan event to the browser part.
139
QApplication::postEvent( m_browser_part, new QCustomEvent( EVENT_SCAN_NETWORK ) );
142
void KonqSidebar_Smb4K::slotSearch()
144
// Load the factory of the config dialog:
145
KLibFactory *search_factory = KLibLoader::self()->factory( "libsmb4ksearchdialog" );
147
if ( search_factory )
149
KDialogBase *searchDialog = new KDialogBase( KDialogBase::Plain, i18n( "Search Dialog" ), KDialogBase::Close,
150
KDialogBase::NoDefault, widget, "sd", true, true );
152
QFrame *frame = searchDialog->plainPage();
154
m_search_part = static_cast<KParts::Part *>( search_factory->create( frame, "SearchDialogPart", "KParts::Part" ) );
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 );
167
//connect( m_search_dialog, SIGNAL( searchResult( Smb4KHostItem * ) ), this, SLOT( slotInsertItem( Smb4KHostItem * ) ) );
169
searchDialog->show();
178
KMessageBox::error( 0, "<qt>"+KLibLoader::self()->lastErrorMessage()+"</qt>" );
184
void KonqSidebar_Smb4K::slotSmb4KOptionsDlg()
186
// Load the factory of the config dialog:
187
KLibFactory *config_factory = KLibLoader::self()->factory( "libsmb4kconfigdialog" );
189
if ( config_factory )
191
KConfigDialog *dlg = static_cast<KConfigDialog *>( config_factory->create( widget, "ConfigDialog", "KConfigDialog" ) );
195
connect( dlg, SIGNAL( settingsChanged() ), this, SLOT( slotSettingsChanged() ) );
202
KMessageBox::error( 0, "<qt>"+KLibLoader::self()->lastErrorMessage()+"</qt>" );
209
void KonqSidebar_Smb4K::slotSettingsChanged()
211
QApplication::postEvent( m_browser_part, new QCustomEvent( EVENT_LOAD_SETTINGS ) );
214
void KonqSidebar_Smb4K::slotMountedShare( const QString &mountedShare )
216
emit openURLRequest( KURL(mountedShare) );
219
void KonqSidebar_Smb4K::slotPrepareUnmount( const QString &mountpoint )
221
if ( QString::compare( currentKonquerorURL, mountpoint ) == 0 )
223
emit openURLRequest( KURL( QDir::home().canonicalPath() ) );
231
#include "smb4k_konqplugin.moc"