From 854bf52eebd2da47ff45f6ae85f4cb89bae89876 Mon Sep 17 00:00:00 2001 From: tpearson Date: Mon, 1 Mar 2010 18:55:11 +0000 Subject: Added old KDE3 version of SMB4K git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/smb4k@1097609 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- plugin/smb4k_konqplugin.cpp | 236 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 236 insertions(+) create mode 100644 plugin/smb4k_konqplugin.cpp (limited to 'plugin/smb4k_konqplugin.cpp') diff --git a/plugin/smb4k_konqplugin.cpp b/plugin/smb4k_konqplugin.cpp new file mode 100644 index 0000000..3cab7fa --- /dev/null +++ b/plugin/smb4k_konqplugin.cpp @@ -0,0 +1,236 @@ +/*************************************************************************** + * Copyright (C) 2004 by Massimo Callegari * + * massimocallegari@yahoo.it * + * * + * 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. * + * * + * 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; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +// Qt includes +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// KDE includes +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// plugin specific includes +// #include "smb4k_konqplugin.moc" +#include "smb4k_konqplugin.h" +#include "../smb4k/core/smb4kcore.h" +#include "../smb4k/core/smb4kdefs.h" + +smb4kWidget::smb4kWidget( QWidget * parent, const char * name, WFlags f ) + : QVBox(parent, name, f) +{ + // Nothing exciting to do ! +} + +KonqSidebar_Smb4K::KonqSidebar_Smb4K(KInstance *inst,QObject *parent,QWidget *widgetParent, QString &desktopName, const char* name): + KonqSidebarPlugin(inst,parent,widgetParent,desktopName,name) +{ + + widget = new smb4kWidget( widgetParent ); + + KToolBar *topBar = new KToolBar( widget, "Topbar" ); + topBar->setIconSize(16); + topBar->insertButton( "reload", 0, SIGNAL( clicked() ), this, SLOT( slotRescan() ) , TRUE, i18n( "Scan Network" ) ); + topBar->insertButton( "find", 1, SIGNAL( clicked() ), this, SLOT( slotSearch() ) , TRUE, i18n( "Search" ) ); + topBar->insertButton( "configure", 2, SIGNAL( clicked() ), this, SLOT( slotSmb4KOptionsDlg() ) , TRUE, i18n( "Configure" ) ); + + // + // Browser widget: + // + KLibFactory *browser_factory = KLibLoader::self()->factory( "libsmb4knetworkbrowser" ); + + if ( browser_factory ) + { + m_browser_part = static_cast( browser_factory->create( widget, "BrowserPart", "KParts::Part", QStringList( "konqplugin=\"true\"" ) ) ); + + // Do nothing here. The network scan (and the mounting of recently used + // shares) will be done by Smb4KCore::init() below. + } + else + { + KMessageBox::error( 0, ""+KLibLoader::self()->lastErrorMessage()+"" ); + + return; + } + + connect( Smb4KCore::mounter(), SIGNAL( mountedShare( const QString &) ), this, SLOT( slotMountedShare( const QString & ) ) ); + connect( Smb4KCore::mounter(), SIGNAL( aboutToUnmount( const QString& ) ), this, SLOT( slotPrepareUnmount( const QString& ) ) ); + + // Scan the network and remount recently used shares: + Smb4KCore::self()->init(); + +} + + +KonqSidebar_Smb4K::~KonqSidebar_Smb4K() +{ + +} + +extern "C" +{ + void* create_konqsidebar_smb4k(KInstance *instance,QObject *par,QWidget *widp,QString &desktopname,const char *name) + { + KGlobal::locale()->insertCatalogue("smb4k"); + return new KonqSidebar_Smb4K(instance,par,widp,desktopname,name); + } +}; + +extern "C" +{ + bool add_konqsidebar_smb4k(QString* fn, QString* /*param*/, QMap *map) + { + map->insert("Type","Link"); + map->insert("Icon","smb4k"); + map->insert("Name",i18n("Samba Browser")); + map->insert("Open","false"); + map->insert("X-KDE-KonqSidebarModule","konqsidebar_smb4k"); + fn->setLatin1("smb4k%1.desktop"); + return true; + } +} + +void KonqSidebar_Smb4K::handleURL(const KURL &url) +{ + currentKonquerorURL = url.path(); + //kdDebug() << "KonqSidebar_Smb4K::handleURL - "<< currentKonquerorURL << endl; +} + +void KonqSidebar_Smb4K::slotRescan() +{ + // Send a custom rescan event to the browser part. + QApplication::postEvent( m_browser_part, new QCustomEvent( EVENT_SCAN_NETWORK ) ); +} + +void KonqSidebar_Smb4K::slotSearch() +{ + // Load the factory of the config dialog: + KLibFactory *search_factory = KLibLoader::self()->factory( "libsmb4ksearchdialog" ); + + if ( search_factory ) + { + KDialogBase *searchDialog = new KDialogBase( KDialogBase::Plain, i18n( "Search Dialog" ), KDialogBase::Close, + KDialogBase::NoDefault, widget, "sd", true, true ); + + QFrame *frame = searchDialog->plainPage(); + + m_search_part = static_cast( search_factory->create( frame, "SearchDialogPart", "KParts::Part" ) ); + + if ( m_search_part ) + { + QGridLayout *layout = new QGridLayout( frame ); + layout->setSpacing( 10 ); + layout->setMargin( 0 ); + layout->addWidget ( m_search_part->widget(), 0, 0, 0 ); + searchDialog->resize(400,300); + // We do not want the dialog to be closed if the user presses return. + // Instead we want that a search is started: + searchDialog->actionButton( KDialogBase::Close )->setAutoDefault( false ); + + //connect( m_search_dialog, SIGNAL( searchResult( Smb4KHostItem * ) ), this, SLOT( slotInsertItem( Smb4KHostItem * ) ) ); + + searchDialog->show(); + } + else + { + delete searchDialog; + } + } + else + { + KMessageBox::error( 0, ""+KLibLoader::self()->lastErrorMessage()+"" ); + + return; + } +} + +void KonqSidebar_Smb4K::slotSmb4KOptionsDlg() +{ + // Load the factory of the config dialog: + KLibFactory *config_factory = KLibLoader::self()->factory( "libsmb4kconfigdialog" ); + + if ( config_factory ) + { + KConfigDialog *dlg = static_cast( config_factory->create( widget, "ConfigDialog", "KConfigDialog" ) ); + + if ( dlg ) + { + connect( dlg, SIGNAL( settingsChanged() ), this, SLOT( slotSettingsChanged() ) ); + + dlg->show(); + } + } + else + { + KMessageBox::error( 0, ""+KLibLoader::self()->lastErrorMessage()+"" ); + + return; + } + +} + +void KonqSidebar_Smb4K::slotSettingsChanged() +{ + QApplication::postEvent( m_browser_part, new QCustomEvent( EVENT_LOAD_SETTINGS ) ); +} + +void KonqSidebar_Smb4K::slotMountedShare( const QString &mountedShare ) +{ + emit openURLRequest( KURL(mountedShare) ); +} + +void KonqSidebar_Smb4K::slotPrepareUnmount( const QString &mountpoint ) +{ + if ( QString::compare( currentKonquerorURL, mountpoint ) == 0 ) + { + emit openURLRequest( KURL( QDir::home().canonicalPath() ) ); + } + else + { + // Nothing to do + } +} + +#include "smb4k_konqplugin.moc" + + + + + -- cgit v1.2.1