File indexing completed on 2023-10-01 08:44:27
0001 /*************************************************************************** 0002 The main window of Smb4K 0003 ------------------- 0004 begin : Di Jan 1 2008 0005 copyright : (C) 2008-2019 by Alexander Reinholdt 0006 email : alexander.reinholdt@kdemail.net 0007 ***************************************************************************/ 0008 0009 /*************************************************************************** 0010 * This program is free software; you can redistribute it and/or modify * 0011 * it under the terms of the GNU General Public License as published by * 0012 * the Free Software Foundation; either version 2 of the License, or * 0013 * (at your option) any later version. * 0014 * * 0015 * This program is distributed in the hope that it will be useful, but * 0016 * WITHOUT ANY WARRANTY; without even the implied warranty of * 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 0018 * General Public License for more details. * 0019 * * 0020 * You should have received a copy of the GNU General Public License * 0021 * along with this program; if not, write to the * 0022 * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,* 0023 * MA 02110-1335, USA * 0024 ***************************************************************************/ 0025 0026 // application specific includes 0027 #include "smb4kmainwindow.h" 0028 #include "smb4ksystemtray.h" 0029 #include "smb4kbookmarkmenu.h" 0030 #include "smb4kprofilesmenu.h" 0031 #include "smb4knetworkbrowserdockwidget.h" 0032 #include "smb4ksharesviewdockwidget.h" 0033 #include "core/smb4ksettings.h" 0034 #include "core/smb4kglobal.h" 0035 #include "core/smb4kwalletmanager.h" 0036 #include "core/smb4kworkgroup.h" 0037 #include "core/smb4khost.h" 0038 #include "core/smb4kshare.h" 0039 #include "core/smb4kfile.h" 0040 #include "core/smb4kmounter.h" 0041 #include "core/smb4ksynchronizer.h" 0042 #include "core/smb4kclient.h" 0043 0044 // Qt includes 0045 #include <QVariantList> 0046 #include <QTimer> 0047 #include <QSize> 0048 #include <QDockWidget> 0049 #include <QMenu> 0050 #include <QActionGroup> 0051 #include <QLabel> 0052 #include <QTabBar> 0053 #include <QMenuBar> 0054 #include <QStatusBar> 0055 #include <QApplication> 0056 0057 // KDE includes 0058 #include <KConfigWidgets/KStandardAction> 0059 #include <KConfigWidgets/KConfigDialog> 0060 #include <KIconThemes/KIconLoader> 0061 #include <KI18n/KLocalizedString> 0062 #include <KCoreAddons/KPluginLoader> 0063 #include <KCoreAddons/KPluginFactory> 0064 #include <KXmlGui/KXMLGUIFactory> 0065 #include <KWidgetsAddons/KMessageBox> 0066 #include "kiconthemes_version.h" 0067 0068 using namespace Smb4KGlobal; 0069 using namespace KParts; 0070 0071 0072 Smb4KMainWindow::Smb4KMainWindow() 0073 : KXmlGuiWindow(), m_system_tray_widget(0) 0074 { 0075 // 0076 // The widget (embedded into the dock widgets) that has the focus 0077 // 0078 m_focusWidget = 0; 0079 0080 // 0081 // Set up main window 0082 // 0083 setStandardToolBarMenuEnabled(true); 0084 createStandardStatusBarAction(); 0085 setDockNestingEnabled(true); 0086 setupActions(); 0087 setupGUI(QSize(800, 600), Default, "smb4k_shell.rc"); 0088 setupView(); 0089 setupMenuBar(); 0090 setupStatusBar(); 0091 setupSystemTrayWidget(); 0092 0093 // 0094 // Set the tab orientation 0095 // 0096 switch (Smb4KSettings::mainWindowTabOrientation()) 0097 { 0098 case Smb4KSettings::EnumMainWindowTabOrientation::Top: 0099 { 0100 setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::North); 0101 break; 0102 } 0103 case Smb4KSettings::EnumMainWindowTabOrientation::Bottom: 0104 { 0105 setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::South); 0106 break; 0107 } 0108 case Smb4KSettings::EnumMainWindowTabOrientation::Left: 0109 { 0110 setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::West); 0111 break; 0112 } 0113 case Smb4KSettings::EnumMainWindowTabOrientation::Right: 0114 { 0115 setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::East); 0116 break; 0117 } 0118 default: 0119 { 0120 break; 0121 } 0122 } 0123 0124 // 0125 // Apply the main window settings 0126 // 0127 setAutoSaveSettings(KConfigGroup(Smb4KSettings::self()->config(), "MainWindow"), true); 0128 0129 // 0130 // Save the setting no matter how the application is closed 0131 // 0132 connect(qApp, &QCoreApplication::aboutToQuit, this, [this] () { saveSettings(); }); 0133 } 0134 0135 0136 Smb4KMainWindow::~Smb4KMainWindow() 0137 { 0138 } 0139 0140 0141 void Smb4KMainWindow::setupActions() 0142 { 0143 // 0144 // Quit action 0145 // 0146 QAction *quit_action = KStandardAction::quit(this, SLOT(slotQuit()), actionCollection()); 0147 actionCollection()->addAction("quit_action", quit_action); 0148 0149 // 0150 // Configure action 0151 // 0152 QAction *configure_action = KStandardAction::preferences(this, SLOT(slotConfigDialog()), actionCollection()); 0153 actionCollection()->addAction("configure_action", configure_action); 0154 0155 // 0156 // Dock widgets action menu 0157 // 0158 KActionMenu *dock_widgets_menu = new KActionMenu(KDE::icon("tab-duplicate"), i18n("Dock Widgets"), actionCollection()); 0159 actionCollection()->addAction("dock_widgets_menu", dock_widgets_menu); 0160 0161 m_dockWidgets = new QActionGroup(actionCollection()); 0162 m_dockWidgets->setExclusive(false); 0163 0164 // 0165 // Bookmarks menu and action 0166 // 0167 Smb4KBookmarkMenu *bookmarksMenu = new Smb4KBookmarkMenu(Smb4KBookmarkMenu::MainWindow, this, this); 0168 QAction *addBookmarkAction = new QAction(KDE::icon("bookmark-new"), i18n("Add &Bookmark"), actionCollection()); 0169 addBookmarkAction->setEnabled(false); 0170 actionCollection()->addAction("bookmarks_menu", bookmarksMenu); 0171 actionCollection()->addAction("bookmark_action", addBookmarkAction); 0172 connect(addBookmarkAction, SIGNAL(triggered(bool)), this, SLOT(slotAddBookmarks())); 0173 connect(bookmarksMenu, SIGNAL(addBookmark()), this, SLOT(slotAddBookmarks())); 0174 0175 // 0176 // Profiles menu 0177 // 0178 Smb4KProfilesMenu *profiles = new Smb4KProfilesMenu(this); 0179 actionCollection()->addAction("profiles_menu", profiles); 0180 } 0181 0182 0183 void Smb4KMainWindow::setupStatusBar() 0184 { 0185 // Set up the progress bar. 0186 m_progress_bar = new QProgressBar(statusBar()); 0187 m_progress_bar->setFixedWidth(100); 0188 m_progress_bar->setMaximum(0); 0189 m_progress_bar->setMinimum(0); 0190 m_progress_bar->setFixedHeight(statusBar()->fontMetrics().height()); 0191 m_progress_bar->setAlignment(Qt::AlignCenter); 0192 m_progress_bar->setVisible(false); 0193 0194 // Set the icon on the right side that represents the initial 0195 // state of the wallet manager. 0196 m_pass_icon = new QLabel(statusBar()); 0197 m_pass_icon->setContentsMargins(0, 0, 0, 0); 0198 m_pass_icon->setAlignment(Qt::AlignCenter); 0199 0200 // The feedback icon. 0201 m_feedback_icon = new QLabel(statusBar()); 0202 m_feedback_icon->setContentsMargins(0, 0, 0, 0); 0203 m_feedback_icon->setAlignment(Qt::AlignCenter); 0204 0205 statusBar()->addPermanentWidget(m_progress_bar); 0206 statusBar()->addPermanentWidget(m_feedback_icon); 0207 statusBar()->addPermanentWidget(m_pass_icon); 0208 0209 slotWalletManagerInitialized(); 0210 setupMountIndicator(); 0211 0212 // 0213 // Connections 0214 // 0215 connect(Smb4KClient::self(), SIGNAL(aboutToStart(NetworkItemPtr,int)), this, SLOT(slotClientAboutToStart(NetworkItemPtr,int))); 0216 connect(Smb4KClient::self(), SIGNAL(finished(NetworkItemPtr,int)), this, SLOT(slotClientFinished(NetworkItemPtr,int))); 0217 0218 connect(Smb4KWalletManager::self(), SIGNAL(initialized()), this, SLOT(slotWalletManagerInitialized())); 0219 0220 connect(Smb4KMounter::self(), SIGNAL(mounted(SharePtr)), this, SLOT(slotVisualMountFeedback(SharePtr))); 0221 connect(Smb4KMounter::self(), SIGNAL(unmounted(SharePtr)), this, SLOT(slotVisualUnmountFeedback(SharePtr))); 0222 connect(Smb4KMounter::self(), SIGNAL(aboutToStart(int)), this, SLOT(slotMounterAboutToStart(int))); 0223 connect(Smb4KMounter::self(), SIGNAL(finished(int)), this, SLOT(slotMounterFinished(int))); 0224 0225 connect(Smb4KSynchronizer::self(), SIGNAL(aboutToStart(QString)), this, SLOT(slotSynchronizerAboutToStart(QString))); 0226 connect(Smb4KSynchronizer::self(), SIGNAL(finished(QString)), this, SLOT(slotSynchronizerFinished(QString))); 0227 } 0228 0229 0230 void Smb4KMainWindow::setupView() 0231 { 0232 // 0233 // We do not set a central widget, because it causes "problems" 0234 // with the dock widgets. We have the nested dock widget property 0235 // set to true, so we can arrange the dock widgets as we like, 0236 // nonetheless. 0237 // 0238 0239 // 0240 // Network browser dock widget 0241 // 0242 Smb4KNetworkBrowserDockWidget *networkBrowserDock = new Smb4KNetworkBrowserDockWidget(i18n("Network Neighborhood"), this); 0243 networkBrowserDock->setObjectName("NetworkBrowserDockWidget"); 0244 networkBrowserDock->setAllowedAreas(Qt::LeftDockWidgetArea); 0245 0246 // Install event filter 0247 networkBrowserDock->widget()->installEventFilter(this); 0248 0249 // Connections 0250 connect(networkBrowserDock, SIGNAL(visibilityChanged(bool)), SLOT(slotNetworkBrowserVisibilityChanged(bool))); 0251 0252 // Add dock widget 0253 addDockWidget(Qt::LeftDockWidgetArea, networkBrowserDock); 0254 0255 // Insert the toggle view mode action to the action group. 0256 m_dockWidgets->addAction(networkBrowserDock->toggleViewAction()); 0257 static_cast<KActionMenu *>(actionCollection()->action("dock_widgets_menu"))->addAction(networkBrowserDock->toggleViewAction()); 0258 0259 // Insert the Network menu 0260 plugActionList("network_menu", networkBrowserDock->actionCollection()->actions()); 0261 0262 // 0263 // Shares view dock widget 0264 // 0265 Smb4KSharesViewDockWidget *sharesViewDock = new Smb4KSharesViewDockWidget(i18n("Mounted Shares"), this); 0266 sharesViewDock->setObjectName("SharesViewDockWidget"); 0267 sharesViewDock->setAllowedAreas(Qt::LeftDockWidgetArea); 0268 0269 // Install event filter 0270 sharesViewDock->widget()->installEventFilter(this); 0271 0272 // Connections 0273 connect(sharesViewDock, SIGNAL(visibilityChanged(bool)), this, SLOT(slotSharesViewVisibilityChanged(bool))); 0274 0275 // Add dock widget 0276 addDockWidget(Qt::LeftDockWidgetArea, sharesViewDock); 0277 0278 // Insert the toggle view mode action to the action group. 0279 m_dockWidgets->addAction(sharesViewDock->toggleViewAction()); 0280 static_cast<KActionMenu *>(actionCollection()->action("dock_widgets_menu"))->addAction(sharesViewDock->toggleViewAction()); 0281 0282 // Insert the Shares menu 0283 plugActionList("shares_menu", sharesViewDock->actionCollection()->actions()); 0284 0285 // 0286 // Initial main window look 0287 // 0288 KConfigGroup configGroup(Smb4KSettings::self()->config(), "MainWindow"); 0289 0290 if (!configGroup.exists()) 0291 { 0292 QList<QDockWidget *> docks = findChildren<QDockWidget *>(); 0293 0294 for (int i = 1; i < docks.size(); ++i) 0295 { 0296 tabifyDockWidget(docks.at(i-1), docks.at(i)); 0297 } 0298 } 0299 } 0300 0301 0302 void Smb4KMainWindow::setupMenuBar() 0303 { 0304 // Get the "Bookmarks" menu 0305 QList<QAction *> actions = menuBar()->actions(); 0306 QListIterator<QAction *> it(actions); 0307 0308 while (it.hasNext()) 0309 { 0310 QAction *action = it.next(); 0311 0312 if (QString::compare("bookmarks", action->objectName()) == 0) 0313 { 0314 Smb4KBookmarkMenu *menu = static_cast<Smb4KBookmarkMenu *>(actionCollection()->action("bookmarks_menu")); 0315 action->setMenu(menu->menu()); 0316 break; 0317 } 0318 else 0319 { 0320 continue; 0321 } 0322 } 0323 } 0324 0325 0326 void Smb4KMainWindow::setupSystemTrayWidget() 0327 { 0328 if (!m_system_tray_widget) 0329 { 0330 m_system_tray_widget = new Smb4KSystemTray(this); 0331 } 0332 0333 connect(m_system_tray_widget, SIGNAL(settingsChanged(QString)), this, SLOT(slotSettingsChanged(QString))); 0334 } 0335 0336 0337 void Smb4KMainWindow::loadSettings() 0338 { 0339 // 0340 // Main window 0341 // 0342 switch (Smb4KSettings::mainWindowTabOrientation()) 0343 { 0344 case Smb4KSettings::EnumMainWindowTabOrientation::Top: 0345 { 0346 setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::North); 0347 break; 0348 } 0349 case Smb4KSettings::EnumMainWindowTabOrientation::Bottom: 0350 { 0351 setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::South); 0352 break; 0353 } 0354 case Smb4KSettings::EnumMainWindowTabOrientation::Left: 0355 { 0356 setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::West); 0357 break; 0358 } 0359 case Smb4KSettings::EnumMainWindowTabOrientation::Right: 0360 { 0361 setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::East); 0362 break; 0363 } 0364 default: 0365 { 0366 break; 0367 } 0368 } 0369 0370 // 0371 // Let the network browser load its settings 0372 // 0373 Smb4KNetworkBrowserDockWidget *networkBrowserDock = findChild<Smb4KNetworkBrowserDockWidget *>(); 0374 0375 if (networkBrowserDock) 0376 { 0377 networkBrowserDock->loadSettings(); 0378 } 0379 0380 // 0381 // Let the shares view load its settings 0382 // 0383 Smb4KSharesViewDockWidget *sharesViewDock = findChild<Smb4KSharesViewDockWidget *>(); 0384 0385 if (sharesViewDock) 0386 { 0387 sharesViewDock->loadSettings(); 0388 } 0389 0390 // 0391 // Reload the list of bookmarks 0392 // 0393 Smb4KBookmarkMenu *bookmarkMenu = findChild<Smb4KBookmarkMenu *>(); 0394 0395 if (bookmarkMenu) 0396 { 0397 bookmarkMenu->refreshMenu(); 0398 } 0399 0400 // Check the state of the password handler and the wallet settings and 0401 // set the pixmap in the status bar accordingly. 0402 slotWalletManagerInitialized(); 0403 0404 // Set up the mount indicator icon. 0405 setupMountIndicator(); 0406 } 0407 0408 0409 void Smb4KMainWindow::saveSettings() 0410 { 0411 // 0412 // Save the settings of the network browser 0413 // 0414 Smb4KNetworkBrowserDockWidget *networkBrowserDock = findChild<Smb4KNetworkBrowserDockWidget *>(); 0415 0416 if (networkBrowserDock) 0417 { 0418 networkBrowserDock->saveSettings(); 0419 } 0420 0421 // 0422 // Let the shares view load its settings 0423 // 0424 Smb4KSharesViewDockWidget *sharesViewDock = findChild<Smb4KSharesViewDockWidget *>(); 0425 0426 if (sharesViewDock) 0427 { 0428 sharesViewDock->saveSettings(); 0429 } 0430 0431 // 0432 // Save if the main window should be started docked. 0433 // 0434 Smb4KSettings::setStartMainWindowDocked(!isVisible()); 0435 0436 // 0437 // Save the settings 0438 // 0439 Smb4KSettings::self()->save(); 0440 } 0441 0442 0443 bool Smb4KMainWindow::queryClose() 0444 { 0445 if (!QApplication::closingDown() && !qApp->isSavingSession() && isVisible()) 0446 { 0447 // This part has been 'stolen' from JuK application. 0448 KMessageBox::information(this, 0449 i18n("<qt>Closing the main window will keep Smb4K running in the system tray. " 0450 "Use <i>Quit</i> from the <i>File</i> menu to quit the application.</qt>"), 0451 i18n("Docking"), "DockToSystemTrayInfo"); 0452 setVisible(false); 0453 return false; 0454 } 0455 else 0456 { 0457 saveSettings(); 0458 return true; 0459 } 0460 } 0461 0462 0463 bool Smb4KMainWindow::eventFilter(QObject *obj, QEvent* e) 0464 { 0465 switch (e->type()) 0466 { 0467 case QEvent::FocusIn: 0468 { 0469 // 0470 // Check if the widget that has the focus belongs to the network 0471 // browser widget 0472 // 0473 Smb4KNetworkBrowserDockWidget *networkBrowserDock = findChild<Smb4KNetworkBrowserDockWidget *>(); 0474 0475 if (networkBrowserDock) 0476 { 0477 QObjectList children = networkBrowserDock->children(); 0478 0479 for (QObject *object : children) 0480 { 0481 if (object == obj) 0482 { 0483 m_focusWidget = networkBrowserDock; 0484 setupDynamicActionList(networkBrowserDock); 0485 break; 0486 } 0487 } 0488 } 0489 0490 // 0491 // Check if the widget that has the focus belongs to the shares 0492 // view 0493 // 0494 Smb4KSharesViewDockWidget *sharesViewDock = findChild<Smb4KSharesViewDockWidget *>(); 0495 0496 if (sharesViewDock) 0497 { 0498 QObjectList children = sharesViewDock->children(); 0499 0500 for (QObject *object : children) 0501 { 0502 if (object == obj) 0503 { 0504 m_focusWidget = sharesViewDock; 0505 setupDynamicActionList(sharesViewDock); 0506 break; 0507 } 0508 } 0509 } 0510 break; 0511 } 0512 default: 0513 { 0514 break; 0515 } 0516 } 0517 0518 return KXmlGuiWindow::eventFilter(obj, e); 0519 } 0520 0521 0522 void Smb4KMainWindow::setupMountIndicator() 0523 { 0524 QStringList overlays; 0525 0526 if (mountedSharesList().size() == 0) 0527 { 0528 m_feedback_icon->setToolTip(i18n("There are currently no shares mounted.")); 0529 } 0530 else 0531 { 0532 #if KICONTHEMES_VERSION < QT_VERSION_CHECK(5,52,0) 0533 overlays << "emblem-mounted"; 0534 #else 0535 overlays << ""; 0536 overlays << "emblem-mounted"; 0537 #endif 0538 m_feedback_icon->setToolTip(i18np("There is currently %1 share mounted.", "There are currently %1 shares mounted.", mountedSharesList().size())); 0539 } 0540 0541 m_feedback_icon->setPixmap(KIconLoader::global()->loadIcon("folder-network", KIconLoader::Small, 0, KIconLoader::DefaultState, overlays)); 0542 } 0543 0544 0545 void Smb4KMainWindow::setupDynamicActionList(QDockWidget* dock) 0546 { 0547 if (dock) 0548 { 0549 // 0550 // Remove all connections to Smb4KMainWindow::slotEnableBookmarkAction() and 0551 // disable the bookmark action. 0552 // 0553 disconnect(this, SLOT(slotEnableBookmarkAction())); 0554 actionCollection()->action("bookmark_action")->setEnabled(false); 0555 0556 // 0557 // Get also the bookmark menu and disable the bookmark action 0558 // there, too. 0559 // 0560 Smb4KBookmarkMenu *bookmarkMenu = findChild<Smb4KBookmarkMenu *>(); 0561 0562 if (bookmarkMenu) 0563 { 0564 bookmarkMenu->setBookmarkActionEnabled(false); 0565 } 0566 0567 // 0568 // Prepare the dynamic action list for the main window 0569 // 0570 QList<QAction *> dynamicList; 0571 KActionCollection *dockActionCollection = 0; 0572 0573 if (dock->objectName() == "NetworkBrowserDockWidget") 0574 { 0575 dockActionCollection = static_cast<Smb4KNetworkBrowserDockWidget *>(dock)->actionCollection(); 0576 } 0577 else if (dock->objectName() == "SharesViewDockWidget") 0578 { 0579 dockActionCollection = static_cast<Smb4KSharesViewDockWidget *>(dock)->actionCollection(); 0580 } 0581 0582 for (QAction *action : dockActionCollection->actions()) 0583 { 0584 if (action->objectName() == "bookmark_action") 0585 { 0586 if (bookmarkMenu) 0587 { 0588 bookmarkMenu->setBookmarkActionEnabled(action->isEnabled()); 0589 connect(action, SIGNAL(changed()), this, SLOT(slotEnableBookmarkAction())); 0590 continue; 0591 } 0592 } 0593 else if (QString::compare(action->objectName(), "filemanager_action") == 0) 0594 { 0595 continue; 0596 } 0597 else if (QString::compare(action->objectName(), "konsole_action") == 0) 0598 { 0599 continue; 0600 } 0601 else if (QString::compare(action->objectName(), "icon_view_action") == 0) 0602 { 0603 continue; 0604 } 0605 else if (QString::compare(action->objectName(), "list_view_action") == 0) 0606 { 0607 continue; 0608 } 0609 0610 dynamicList << action; 0611 } 0612 0613 // 0614 // Remove old and insert new dynamic action list 0615 // 0616 unplugActionList("dynamic_list"); 0617 plugActionList("dynamic_list", dynamicList); 0618 } 0619 } 0620 0621 0622 0623 ///////////////////////////////////////////////////////////////////////////// 0624 // SLOT IMPLEMENTATIONS 0625 ///////////////////////////////////////////////////////////////////////////// 0626 0627 void Smb4KMainWindow::slotQuit() 0628 { 0629 // 0630 // Save the settings. Work around queryClose() not being called. :( 0631 // 0632 saveSettings(); 0633 0634 // 0635 // Quit the application 0636 // 0637 qApp->quit(); 0638 } 0639 0640 0641 void Smb4KMainWindow::slotConfigDialog() 0642 { 0643 // 0644 // Check if the configuration dialog exists and try to show it. 0645 // 0646 if (KConfigDialog::exists("Smb4KConfigDialog")) 0647 { 0648 KConfigDialog::showDialog("Smb4KConfigDialog"); 0649 return; 0650 } 0651 0652 // 0653 // If the dialog does not exist, load and show it: 0654 // 0655 KPluginLoader loader("smb4kconfigdialog"); 0656 KPluginFactory *configFactory = loader.factory(); 0657 0658 if (configFactory) 0659 { 0660 KConfigDialog *dlg = configFactory->create<KConfigDialog>(this); 0661 0662 if (dlg) 0663 { 0664 dlg->setObjectName("Smb4KConfigDialog"); 0665 connect(dlg, SIGNAL(settingsChanged(QString)), this, SLOT(slotSettingsChanged(QString)), Qt::UniqueConnection); 0666 connect(dlg, SIGNAL(settingsChanged(QString)), m_system_tray_widget, SLOT(slotSettingsChanged(QString)), Qt::UniqueConnection); 0667 dlg->show(); 0668 } 0669 } 0670 else 0671 { 0672 KMessageBox::error(0, "<qt>"+loader.errorString()+"</qt>"); 0673 return; 0674 } 0675 } 0676 0677 0678 void Smb4KMainWindow::slotSettingsChanged(const QString &) 0679 { 0680 loadSettings(); 0681 } 0682 0683 0684 void Smb4KMainWindow::slotAddBookmarks() 0685 { 0686 // 0687 // If we have a widget that has the focus, trigger its 'Add Bookmark' 0688 // action to add bookmarks. 0689 // 0690 if (m_focusWidget) 0691 { 0692 if (QString::compare(m_focusWidget->metaObject()->className(), "Smb4KNetworkBrowserDockWidget") == 0) 0693 { 0694 Smb4KNetworkBrowserDockWidget *dockWidget = qobject_cast<Smb4KNetworkBrowserDockWidget *>(m_focusWidget); 0695 0696 if (dockWidget) 0697 { 0698 QAction *action = dockWidget->actionCollection()->action("bookmark_action"); 0699 0700 // Only trigger the action if it is enabled 0701 if (action && action->isEnabled()) 0702 { 0703 action->trigger(); 0704 } 0705 } 0706 } 0707 else if (QString::compare(m_focusWidget->metaObject()->className(), "Smb4KSharesViewDockWidget") == 0) 0708 { 0709 Smb4KSharesViewDockWidget *dockWidget = qobject_cast<Smb4KSharesViewDockWidget *>(m_focusWidget); 0710 0711 if (dockWidget) 0712 { 0713 QAction *action = dockWidget->actionCollection()->action("bookmark_action"); 0714 0715 // Only trigger the action if it is enabled 0716 if (action && action->isEnabled()) 0717 { 0718 action->trigger(); 0719 } 0720 } 0721 } 0722 } 0723 } 0724 0725 0726 void Smb4KMainWindow::slotWalletManagerInitialized() 0727 { 0728 if (Smb4KWalletManager::self()->useWalletSystem()) 0729 { 0730 if (KIconLoader::global()->hasIcon("kwalletmanager")) 0731 { 0732 m_pass_icon->setPixmap(KIconLoader::global()->loadIcon("kwalletmanager", 0733 KIconLoader::Small, 0, KIconLoader::DefaultState)); 0734 } 0735 else 0736 { 0737 m_pass_icon->setPixmap(KIconLoader::global()->loadIcon("security-high", 0738 KIconLoader::Small, 0, KIconLoader::DefaultState)); 0739 } 0740 0741 m_pass_icon->setToolTip(i18n("The wallet is used.")); 0742 } 0743 else 0744 { 0745 m_pass_icon->setPixmap(KIconLoader::global()->loadIcon("dialog-password", 0746 KIconLoader::Small, 0, KIconLoader::DefaultState)); 0747 m_pass_icon->setToolTip(i18n("The password dialog is used.")); 0748 } 0749 } 0750 0751 0752 void Smb4KMainWindow::slotClientAboutToStart(const NetworkItemPtr &item, int process) 0753 { 0754 Q_ASSERT(item); 0755 0756 switch (process) 0757 { 0758 case LookupDomains: 0759 { 0760 statusBar()->showMessage(i18n("Looking for workgroups and domains..."), 0); 0761 break; 0762 } 0763 case LookupDomainMembers: 0764 { 0765 WorkgroupPtr workgroup = item.staticCast<Smb4KWorkgroup>(); 0766 statusBar()->showMessage(i18n("Looking for hosts in domain %1...", workgroup->workgroupName()), 0); 0767 break; 0768 } 0769 case LookupShares: 0770 { 0771 HostPtr host = item.staticCast<Smb4KHost>(); 0772 statusBar()->showMessage(i18n("Looking for shares provided by host %1...", host->hostName()), 0); 0773 break; 0774 } 0775 case LookupFiles: 0776 { 0777 QString message; 0778 0779 switch (item->type()) 0780 { 0781 case Share: 0782 { 0783 message = i18n("Looking for files and directories in %1...", item.staticCast<Smb4KShare>()->displayString()); 0784 break; 0785 } 0786 case Directory: 0787 { 0788 FilePtr file = item.staticCast<Smb4KFile>(); 0789 0790 for (const SharePtr &s : sharesList()) 0791 { 0792 if (s->workgroupName() == file->workgroupName() && s->hostName() == file->hostName() && s->shareName() == file->shareName()) 0793 { 0794 message = i18n("Looking for files and directories in %1...", s->displayString()); 0795 break; 0796 } 0797 } 0798 0799 break; 0800 } 0801 default: 0802 { 0803 break; 0804 } 0805 } 0806 0807 statusBar()->showMessage(message, 0); 0808 0809 break; 0810 } 0811 case WakeUp: 0812 { 0813 statusBar()->showMessage(i18n("Waking up remote hosts..."), 0); 0814 break; 0815 } 0816 case PrintFile: 0817 { 0818 SharePtr share = item.staticCast<Smb4KShare>(); 0819 statusBar()->showMessage(i18n("Sending file to printer %1...", share->displayString()), 0); 0820 break; 0821 } 0822 case NetworkSearch: 0823 { 0824 statusBar()->showMessage(i18n("Searching..."), 0); 0825 break; 0826 } 0827 default: 0828 { 0829 break; 0830 } 0831 } 0832 0833 if (!m_progress_bar->isVisible()) 0834 { 0835 m_progress_bar->setVisible(true); 0836 } 0837 } 0838 0839 0840 void Smb4KMainWindow::slotClientFinished(const NetworkItemPtr &/*item*/, int /*process*/) 0841 { 0842 if (!coreIsRunning()) 0843 { 0844 m_progress_bar->setVisible(false); 0845 m_progress_bar->reset(); 0846 statusBar()->showMessage(i18n("Done."), 2000); 0847 } 0848 } 0849 0850 0851 void Smb4KMainWindow::slotMounterAboutToStart(int process) 0852 { 0853 // Tell the user which action is performed by the mounter: 0854 // mounting, unmounting or waking up. 0855 switch (process) 0856 { 0857 case MountShare: 0858 { 0859 statusBar()->showMessage(i18n("Mounting..."), 0); 0860 break; 0861 } 0862 case UnmountShare: 0863 { 0864 statusBar()->showMessage(i18n("Unmounting..."), 0); 0865 break; 0866 } 0867 case WakeUp: 0868 { 0869 statusBar()->showMessage(i18n("Waking up host..."), 0); 0870 break; 0871 } 0872 default: 0873 { 0874 break; 0875 } 0876 } 0877 0878 if (!m_progress_bar->isVisible()) 0879 { 0880 m_progress_bar->setVisible(true); 0881 } 0882 } 0883 0884 0885 void Smb4KMainWindow::slotMounterFinished(int /*process*/) 0886 { 0887 QTimer::singleShot(250, [this] () { 0888 if (!coreIsRunning()) 0889 { 0890 m_progress_bar->setVisible(false); 0891 m_progress_bar->reset(); 0892 statusBar()->showMessage(i18n("Done."), 2000); 0893 } 0894 }); 0895 } 0896 0897 0898 void Smb4KMainWindow::slotVisualMountFeedback(const SharePtr &share) 0899 { 0900 Q_ASSERT(share); 0901 0902 if (share) 0903 { 0904 m_feedback_icon->setPixmap(KIconLoader::global()->loadIcon("dialog-ok", 0905 KIconLoader::Small, 0, KIconLoader::DefaultState)); 0906 m_feedback_icon->setToolTip(i18n("%1 has been mounted successfully.", share->displayString())); 0907 0908 QList<QTabBar *> list = findChildren<QTabBar *>(); 0909 QDockWidget *shares_dock = findChild<QDockWidget *>("SharesViewDockWidget"); 0910 0911 if (shares_dock) 0912 { 0913 for (int i = 0; i < list.size(); ++i) 0914 { 0915 if (list.at(i)->count() != 0) 0916 { 0917 for (int j = 0; j < list.at(i)->count(); ++j) 0918 { 0919 if (QString::compare(shares_dock->windowTitle(), list.at(i)->tabText(j)) == 0 && 0920 list.at(i)->currentIndex() != j) 0921 { 0922 list.at(i)->setTabTextColor(j, palette().highlightedText().color()) ; 0923 break; 0924 } 0925 else 0926 { 0927 continue; 0928 } 0929 } 0930 continue; 0931 } 0932 else 0933 { 0934 continue; 0935 } 0936 } 0937 } 0938 0939 QTimer::singleShot(2000, this, SLOT(slotEndVisualFeedback())); 0940 } 0941 } 0942 0943 0944 void Smb4KMainWindow::slotVisualUnmountFeedback(const SharePtr &share) 0945 { 0946 Q_ASSERT(share); 0947 0948 if (share) 0949 { 0950 m_feedback_icon->setPixmap(KIconLoader::global()->loadIcon("dialog-ok", 0951 KIconLoader::Small, 0, KIconLoader::DefaultState)); 0952 m_feedback_icon->setToolTip(i18n("%1 has been unmounted successfully.", share->displayString())); 0953 0954 QList<QTabBar *> list = findChildren<QTabBar *>(); 0955 QDockWidget *shares_dock = findChild<QDockWidget *>("SharesViewDockWidget"); 0956 0957 if (shares_dock) 0958 { 0959 for (int i = 0; i < list.size(); ++i) 0960 { 0961 if (list.at(i)->count() != 0) 0962 { 0963 for (int j = 0; j < list.at(i)->count(); ++j) 0964 { 0965 if (QString::compare(shares_dock->windowTitle(), list.at(i)->tabText(j)) == 0 && 0966 list.at(i)->currentIndex() != j) 0967 { 0968 list.at(i)->setTabTextColor(j, palette().highlightedText().color()) ; 0969 break; 0970 } 0971 else 0972 { 0973 continue; 0974 } 0975 } 0976 continue; 0977 } 0978 else 0979 { 0980 continue; 0981 } 0982 } 0983 } 0984 0985 QTimer::singleShot(2000, this, SLOT(slotEndVisualFeedback())); 0986 } 0987 } 0988 0989 0990 void Smb4KMainWindow::slotEndVisualFeedback() 0991 { 0992 QList<QTabBar *> list = findChildren<QTabBar *>(); 0993 QDockWidget *shares_dock = findChild<QDockWidget *>("SharesViewDockWidget"); 0994 0995 if (shares_dock) 0996 { 0997 for (int i = 0; i < list.size(); ++i) 0998 { 0999 if (list.at(i)->count() != 0) 1000 { 1001 for (int j = 0; j < list.at(i)->count(); ++j) 1002 { 1003 if (QString::compare(shares_dock->windowTitle(), list.at(i)->tabText(j)) == 0) 1004 { 1005 list.at(i)->setTabTextColor(j, palette().text().color()) ; 1006 break; 1007 } 1008 else 1009 { 1010 continue; 1011 } 1012 } 1013 1014 continue; 1015 } 1016 else 1017 { 1018 continue; 1019 } 1020 } 1021 } 1022 1023 setupMountIndicator(); 1024 } 1025 1026 1027 void Smb4KMainWindow::slotSynchronizerAboutToStart(const QString &dest) 1028 { 1029 statusBar()->showMessage(i18n("Synchronizing %1", dest), 0); 1030 1031 if (!m_progress_bar->isVisible()) 1032 { 1033 m_progress_bar->setVisible(true); 1034 } 1035 } 1036 1037 1038 void Smb4KMainWindow::slotSynchronizerFinished(const QString &/*dest*/) 1039 { 1040 if (!coreIsRunning()) 1041 { 1042 m_progress_bar->setVisible(false); 1043 m_progress_bar->reset(); 1044 statusBar()->showMessage(i18n("Done."), 2000); 1045 } 1046 } 1047 1048 1049 void Smb4KMainWindow::slotEnableBookmarkAction() 1050 { 1051 // 1052 // Get the focused widget's 'Add Bookmark' action and read its 1053 // isEnabled() property. Set the action of the main window and the 1054 // bookmark menu respectively. 1055 // 1056 if (m_focusWidget) 1057 { 1058 if (QString::compare(m_focusWidget->metaObject()->className(), "Smb4KNetworkBrowserDockWidget") == 0) 1059 { 1060 Smb4KNetworkBrowserDockWidget *dockWidget = qobject_cast<Smb4KNetworkBrowserDockWidget *>(m_focusWidget); 1061 1062 if (dockWidget) 1063 { 1064 QAction *action = dockWidget->actionCollection()->action("bookmark_action"); 1065 1066 if (action) 1067 { 1068 // Bookmark action of the main window 1069 actionCollection()->action("bookmark_action")->setEnabled(action->isEnabled()); 1070 1071 // Bookmark action of the bookmark menu 1072 Smb4KBookmarkMenu *bookmarkMenu = findChild<Smb4KBookmarkMenu *>(); 1073 1074 if (bookmarkMenu) 1075 { 1076 bookmarkMenu->setBookmarkActionEnabled(action->isEnabled()); 1077 } 1078 } 1079 } 1080 } 1081 else if (QString::compare(m_focusWidget->metaObject()->className(), "Smb4KSharesViewDockWidget") == 0) 1082 { 1083 Smb4KSharesViewDockWidget *dockWidget = static_cast<Smb4KSharesViewDockWidget *>(m_focusWidget); 1084 1085 if (dockWidget) 1086 { 1087 QAction *action = dockWidget->actionCollection()->action("bookmark_action"); 1088 1089 if (action) 1090 { 1091 // Bookmark action of the main window 1092 actionCollection()->action("bookmark_action")->setEnabled(action->isEnabled()); 1093 1094 // Bookmark action of the bookmark menu 1095 Smb4KBookmarkMenu *bookmarkMenu = findChild<Smb4KBookmarkMenu *>(); 1096 1097 if (bookmarkMenu) 1098 { 1099 bookmarkMenu->setBookmarkActionEnabled(action->isEnabled()); 1100 } 1101 } 1102 } 1103 } 1104 } 1105 } 1106 1107 1108 void Smb4KMainWindow::slotNetworkBrowserVisibilityChanged(bool visible) 1109 { 1110 QDockWidget *dock = findChild<Smb4KNetworkBrowserDockWidget *>(); 1111 1112 if (dock) 1113 { 1114 if (visible) 1115 { 1116 dock->widget()->setFocus(); 1117 } 1118 else 1119 { 1120 dock->widget()->clearFocus(); 1121 } 1122 } 1123 } 1124 1125 1126 void Smb4KMainWindow::slotSharesViewVisibilityChanged(bool visible) 1127 { 1128 QDockWidget *dock = findChild<Smb4KSharesViewDockWidget *>(); 1129 1130 if (dock) 1131 { 1132 if (visible) 1133 { 1134 dock->widget()->setFocus(); 1135 } 1136 else 1137 { 1138 dock->widget()->clearFocus(); 1139 } 1140 } 1141 } 1142