File indexing completed on 2023-10-01 08:44:28
0001 /*************************************************************************** 0002 The network neighborhood browser dock widget 0003 ------------------- 0004 begin : Sat Apr 28 2018 0005 copyright : (C) 2018-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 #ifdef HAVE_CONFIG_H 0027 #include <config.h> 0028 #endif 0029 0030 // application specific includes 0031 #include "smb4knetworkbrowserdockwidget.h" 0032 #include "smb4knetworkbrowseritem.h" 0033 #include "core/smb4kmounter.h" 0034 #include "core/smb4kworkgroup.h" 0035 #include "core/smb4khost.h" 0036 #include "core/smb4kshare.h" 0037 #include "core/smb4ksettings.h" 0038 #include "core/smb4kbookmarkhandler.h" 0039 #include "core/smb4kwalletmanager.h" 0040 #include "core/smb4kcustomoptionsmanager.h" 0041 #include "core/smb4kclient.h" 0042 0043 // Qt includes 0044 #include <QApplication> 0045 #include <QMenu> 0046 #include <QHeaderView> 0047 #include <QVBoxLayout> 0048 #include <QTreeWidgetItemIterator> 0049 0050 // KDE includes 0051 #include <KWidgetsAddons/KDualAction> 0052 #include <KWidgetsAddons/KGuiItem> 0053 #include <KI18n/KLocalizedString> 0054 #include <KIconThemes/KIconLoader> 0055 0056 using namespace Smb4KGlobal; 0057 0058 0059 Smb4KNetworkBrowserDockWidget::Smb4KNetworkBrowserDockWidget(const QString& title, QWidget* parent) 0060 : QDockWidget(title, parent) 0061 { 0062 // 0063 // The network browser widget 0064 // 0065 QWidget *mainWidget = new QWidget(this); 0066 QVBoxLayout *mainWidgetLayout = new QVBoxLayout(mainWidget); 0067 mainWidgetLayout->setMargin(0); 0068 mainWidgetLayout->setSpacing(5); 0069 0070 m_networkBrowser = new Smb4KNetworkBrowser(mainWidget); 0071 m_searchToolBar = new Smb4KNetworkSearchToolBar(mainWidget); 0072 m_searchToolBar->setVisible(false); 0073 0074 mainWidgetLayout->addWidget(m_networkBrowser); 0075 mainWidgetLayout->addWidget(m_searchToolBar); 0076 0077 setWidget(mainWidget); 0078 0079 // 0080 // The action collection 0081 // 0082 m_actionCollection = new KActionCollection(this); 0083 0084 // 0085 // The context menu 0086 // 0087 m_contextMenu = new KActionMenu(this); 0088 0089 // 0090 // Search underway? 0091 // 0092 m_searchRunning = false; 0093 0094 // 0095 // Set up the actions 0096 // 0097 setupActions(); 0098 0099 // 0100 // Load the settings 0101 // 0102 loadSettings(); 0103 0104 // 0105 // Connections 0106 // 0107 connect(m_networkBrowser, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(slotContextMenuRequested(QPoint))); 0108 connect(m_networkBrowser, SIGNAL(itemActivated(QTreeWidgetItem*,int)), this, SLOT(slotItemActivated(QTreeWidgetItem*,int))); 0109 connect(m_networkBrowser, SIGNAL(itemSelectionChanged()), this, SLOT(slotItemSelectionChanged())); 0110 0111 connect(m_searchToolBar, SIGNAL(close()), this, SLOT(slotHideSearchToolBar())); 0112 connect(m_searchToolBar, SIGNAL(search(QString)), this, SLOT(slotPerformSearch(QString))); 0113 connect(m_searchToolBar, SIGNAL(abort()), this, SLOT(slotStopSearch())); 0114 connect(m_searchToolBar, SIGNAL(jumpToResult(QString)), this, SLOT(slotJumpToResult(QString))); 0115 connect(m_searchToolBar, SIGNAL(clearSearchResults()), this, SLOT(slotClearSearchResults())); 0116 0117 connect(Smb4KClient::self(), SIGNAL(aboutToStart(NetworkItemPtr,int)), this, SLOT(slotClientAboutToStart(NetworkItemPtr,int))); 0118 connect(Smb4KClient::self(), SIGNAL(finished(NetworkItemPtr,int)), this, SLOT(slotClientFinished(NetworkItemPtr,int))); 0119 connect(Smb4KClient::self(), SIGNAL(workgroups()), this, SLOT(slotWorkgroups())); 0120 connect(Smb4KClient::self(), SIGNAL(hosts(WorkgroupPtr)), this, SLOT(slotWorkgroupMembers(WorkgroupPtr))); 0121 connect(Smb4KClient::self(), SIGNAL(shares(HostPtr)), this, SLOT(slotShares(HostPtr))); 0122 connect(Smb4KClient::self(), SIGNAL(searchResults(QList<SharePtr>)), this, SLOT(slotSearchResults(QList<SharePtr>))); 0123 0124 connect(Smb4KMounter::self(), SIGNAL(mounted(SharePtr)), this, SLOT(slotShareMounted(SharePtr))); 0125 connect(Smb4KMounter::self(), SIGNAL(unmounted(SharePtr)), this, SLOT(slotShareUnmounted(SharePtr))); 0126 connect(Smb4KMounter::self(), SIGNAL(aboutToStart(int)), this, SLOT(slotMounterAboutToStart(int))); 0127 connect(Smb4KMounter::self(), SIGNAL(finished(int)), this, SLOT(slotMounterFinished(int))); 0128 0129 connect(KIconLoader::global(), SIGNAL(iconChanged(int)), this, SLOT(slotIconSizeChanged(int))); 0130 } 0131 0132 0133 Smb4KNetworkBrowserDockWidget::~Smb4KNetworkBrowserDockWidget() 0134 { 0135 } 0136 0137 0138 void Smb4KNetworkBrowserDockWidget::setupActions() 0139 { 0140 // 0141 // Rescan and abort dual action 0142 // 0143 KDualAction *rescanAbortAction = new KDualAction(this); 0144 rescanAbortAction->setInactiveIcon(KDE::icon("view-refresh")); 0145 rescanAbortAction->setInactiveText(i18n("Scan Netwo&rk")); 0146 rescanAbortAction->setActiveIcon(KDE::icon("process-stop")); 0147 rescanAbortAction->setActiveText(i18n("&Abort")); 0148 rescanAbortAction->setAutoToggle(false); 0149 rescanAbortAction->setEnabled(true); 0150 0151 connect(rescanAbortAction, SIGNAL(triggered(bool)), this, SLOT(slotRescanAbortActionTriggered(bool))); 0152 0153 m_actionCollection->addAction("rescan_abort_action", rescanAbortAction); 0154 m_actionCollection->setDefaultShortcut(rescanAbortAction, QKeySequence::Refresh); 0155 0156 // 0157 // Search action 0158 // 0159 QAction *searchAction = new QAction(KDE::icon("search"), i18n("&Search"), this); 0160 0161 connect(searchAction, SIGNAL(triggered(bool)), this, SLOT(slotShowSearchToolBar())); 0162 0163 m_actionCollection->addAction("search_action", searchAction); 0164 m_actionCollection->setDefaultShortcut(searchAction, QKeySequence::Find); 0165 0166 // 0167 // Separator 0168 // 0169 QAction *separator1 = new QAction(this); 0170 separator1->setSeparator(true); 0171 0172 m_actionCollection->addAction("network_separator1", separator1); 0173 0174 // 0175 // Bookmark action 0176 // 0177 QAction *bookmarkAction = new QAction(KDE::icon("bookmark-new"), i18n("Add &Bookmark"), this); 0178 bookmarkAction->setEnabled(false); 0179 0180 connect(bookmarkAction, SIGNAL(triggered(bool)), this, SLOT(slotAddBookmark(bool))); 0181 0182 m_actionCollection->addAction("bookmark_action", bookmarkAction); 0183 m_actionCollection->setDefaultShortcut(bookmarkAction, QKeySequence(Qt::CTRL+Qt::Key_B)); 0184 0185 0186 // 0187 // Mount dialog action 0188 // 0189 QAction *manualAction = new QAction(KDE::icon("view-form", QStringList("emblem-mounted")), i18n("&Open Mount Dialog"), this); 0190 manualAction->setEnabled(true); 0191 0192 connect(manualAction, SIGNAL(triggered(bool)), this, SLOT(slotMountManually(bool))); 0193 0194 m_actionCollection->addAction("mount_manually_action", manualAction); 0195 m_actionCollection->setDefaultShortcut(manualAction, QKeySequence(Qt::CTRL+Qt::Key_O)); 0196 0197 // 0198 // Separator 0199 // 0200 QAction *separator2 = new QAction(this); 0201 separator2->setSeparator(true); 0202 0203 m_actionCollection->addAction("network_separator2", separator2); 0204 0205 // 0206 // Authentication action 0207 // 0208 QAction *authAction = new QAction(KDE::icon("dialog-password"), i18n("Au&thentication"), this); 0209 authAction->setEnabled(false); 0210 0211 connect(authAction, SIGNAL(triggered(bool)), this, SLOT(slotAuthentication(bool))); 0212 0213 m_actionCollection->addAction("authentication_action", authAction); 0214 m_actionCollection->setDefaultShortcut(authAction, QKeySequence(Qt::CTRL+Qt::Key_T)); 0215 0216 // 0217 // Custom options action 0218 // 0219 QAction *customAction = new QAction(KDE::icon("preferences-system-network"), i18n("&Custom Options"), this); 0220 customAction->setEnabled(false); 0221 0222 connect(customAction, SIGNAL(triggered(bool)), this, SLOT(slotCustomOptions(bool))); 0223 0224 m_actionCollection->addAction("custom_action", customAction); 0225 m_actionCollection->setDefaultShortcut(customAction, QKeySequence(Qt::CTRL+Qt::Key_C)); 0226 0227 // 0228 // Preview action 0229 // 0230 QAction *previewAction = new QAction(KDE::icon("view-list-icons"), i18n("Pre&view"), this); 0231 previewAction->setEnabled(false); 0232 0233 connect(previewAction, SIGNAL(triggered(bool)), this, SLOT(slotPreview(bool))); 0234 0235 m_actionCollection->addAction("preview_action", previewAction); 0236 m_actionCollection->setDefaultShortcut(previewAction, QKeySequence(Qt::CTRL+Qt::Key_V)); 0237 0238 // 0239 // Print action 0240 // 0241 QAction *printAction = new QAction(KDE::icon("printer"), i18n("&Print File"), this); 0242 printAction->setEnabled(false); 0243 0244 connect(printAction, SIGNAL(triggered(bool)), this, SLOT(slotPrint(bool))); 0245 0246 m_actionCollection->addAction("print_action", printAction); 0247 m_actionCollection->setDefaultShortcut(printAction, QKeySequence(Qt::CTRL+Qt::Key_P)); 0248 0249 // 0250 // Mount/unmount action 0251 // 0252 KDualAction *mountAction = new KDualAction(this); 0253 KGuiItem mountItem(i18n("&Mount"), KDE::icon("media-mount")); 0254 KGuiItem unmountItem(i18n("&Unmount"), KDE::icon("media-eject")); 0255 mountAction->setActiveGuiItem(mountItem); 0256 mountAction->setInactiveGuiItem(unmountItem); 0257 mountAction->setActive(true); 0258 mountAction->setAutoToggle(false); 0259 mountAction->setEnabled(false); 0260 0261 connect(mountAction, SIGNAL(triggered(bool)), this, SLOT(slotMountActionTriggered(bool))); 0262 connect(mountAction, SIGNAL(activeChanged(bool)), this, SLOT(slotMountActionChanged(bool))); 0263 0264 m_actionCollection->addAction("mount_action", mountAction); 0265 m_actionCollection->setDefaultShortcut(mountAction, QKeySequence(Qt::CTRL+Qt::Key_M)); 0266 0267 // 0268 // Plug the actions into the context menu 0269 // 0270 for (QAction *a : m_actionCollection->actions()) 0271 { 0272 m_contextMenu->addAction(a); 0273 } 0274 } 0275 0276 0277 void Smb4KNetworkBrowserDockWidget::loadSettings() 0278 { 0279 // 0280 // Load icon size 0281 // 0282 int iconSize = KIconLoader::global()->currentSize(KIconLoader::Small); 0283 m_networkBrowser->setIconSize(QSize(iconSize, iconSize)); 0284 0285 // 0286 // Show/hide columns 0287 // 0288 m_networkBrowser->setColumnHidden(Smb4KNetworkBrowser::IP, !Smb4KSettings::showIPAddress()); 0289 m_networkBrowser->setColumnHidden(Smb4KNetworkBrowser::Type, !Smb4KSettings::showType()); 0290 m_networkBrowser->setColumnHidden(Smb4KNetworkBrowser::Comment, !Smb4KSettings::showComment()); 0291 0292 // 0293 // Load and apply the positions of the columns 0294 // 0295 KConfigGroup configGroup(Smb4KSettings::self()->config(), "NetworkBrowserPart"); 0296 0297 QMap<int, int> map; 0298 map.insert(configGroup.readEntry("ColumnPositionNetwork", (int)Smb4KNetworkBrowser::Network), Smb4KNetworkBrowser::Network); 0299 map.insert(configGroup.readEntry("ColumnPositionType", (int)Smb4KNetworkBrowser::Type), Smb4KNetworkBrowser::Type); 0300 map.insert(configGroup.readEntry("ColumnPositionIP", (int)Smb4KNetworkBrowser::IP), Smb4KNetworkBrowser::IP); 0301 map.insert(configGroup.readEntry("ColumnPositionComment", (int)Smb4KNetworkBrowser::Comment), Smb4KNetworkBrowser::Comment); 0302 0303 QMap<int, int>::const_iterator it = map.constBegin(); 0304 0305 while (it != map.constEnd()) 0306 { 0307 if (it.key() != m_networkBrowser->header()->visualIndex(it.value())) 0308 { 0309 m_networkBrowser->header()->moveSection(m_networkBrowser->header()->visualIndex(it.value()), it.key()); 0310 } 0311 0312 ++it; 0313 } 0314 0315 // 0316 // Apply the completion strings to the search toolbar 0317 // 0318 m_searchToolBar->setCompletionStrings(configGroup.readEntry("SearchItemCompletion", QStringList())); 0319 0320 // 0321 // Does anything has to be changed with the marked shares? 0322 // 0323 for (const SharePtr &share : mountedSharesList()) 0324 { 0325 // We do not need to use slotShareUnmounted() here, too, 0326 // because slotShareMounted() will take care of everything 0327 // we need here. 0328 slotShareMounted(share); 0329 } 0330 0331 // 0332 // Adjust the actions, if needed 0333 // 0334 slotItemSelectionChanged(); 0335 } 0336 0337 0338 void Smb4KNetworkBrowserDockWidget::saveSettings() 0339 { 0340 // 0341 // Save the position of the columns 0342 // 0343 KConfigGroup configGroup(Smb4KSettings::self()->config(), "NetworkBrowserPart"); 0344 configGroup.writeEntry("ColumnPositionNetwork", m_networkBrowser->header()->visualIndex(Smb4KNetworkBrowser::Network)); 0345 configGroup.writeEntry("ColumnPositionType", m_networkBrowser->header()->visualIndex(Smb4KNetworkBrowser::Type)); 0346 configGroup.writeEntry("ColumnPositionIP", m_networkBrowser->header()->visualIndex(Smb4KNetworkBrowser::IP)); 0347 configGroup.writeEntry("ColumnPositionComment", m_networkBrowser->header()->visualIndex(Smb4KNetworkBrowser::Comment)); 0348 0349 // 0350 // Save the completion strings 0351 // 0352 configGroup.writeEntry("SearchItemCompletion", m_searchToolBar->completionStrings()); 0353 0354 configGroup.sync(); 0355 } 0356 0357 0358 KActionCollection *Smb4KNetworkBrowserDockWidget::actionCollection() 0359 { 0360 return m_actionCollection; 0361 } 0362 0363 0364 void Smb4KNetworkBrowserDockWidget::slotContextMenuRequested(const QPoint& pos) 0365 { 0366 m_contextMenu->menu()->popup(m_networkBrowser->viewport()->mapToGlobal(pos)); 0367 } 0368 0369 0370 void Smb4KNetworkBrowserDockWidget::slotItemActivated(QTreeWidgetItem* item, int /*column*/) 0371 { 0372 // 0373 // Process the activated item 0374 // 0375 if (QApplication::keyboardModifiers() == Qt::NoModifier && m_networkBrowser->selectedItems().size() == 1) 0376 { 0377 Smb4KNetworkBrowserItem *browserItem = static_cast<Smb4KNetworkBrowserItem *>(item); 0378 0379 if (browserItem) 0380 { 0381 switch (browserItem->type()) 0382 { 0383 case Workgroup: 0384 { 0385 if (browserItem->isExpanded()) 0386 { 0387 Smb4KClient::self()->lookupDomainMembers(browserItem->workgroupItem()); 0388 } 0389 break; 0390 } 0391 case Host: 0392 { 0393 if (browserItem->isExpanded()) 0394 { 0395 Smb4KClient::self()->lookupShares(browserItem->hostItem()); 0396 } 0397 break; 0398 } 0399 case Share: 0400 { 0401 if (!browserItem->shareItem()->isPrinter()) 0402 { 0403 slotMountActionTriggered(false); // boolean is ignored 0404 } 0405 else 0406 { 0407 slotPrint(false); // boolean is ignored 0408 } 0409 break; 0410 } 0411 default: 0412 { 0413 break; 0414 } 0415 } 0416 } 0417 } 0418 } 0419 0420 0421 void Smb4KNetworkBrowserDockWidget::slotItemSelectionChanged() 0422 { 0423 // 0424 // Get the selected item 0425 // 0426 QList<QTreeWidgetItem *> items = m_networkBrowser->selectedItems(); 0427 0428 // 0429 // Enable/disable and/or adjust the actions depending of the number 0430 // of selected items and their type 0431 // 0432 if (items.size() == 1) 0433 { 0434 Smb4KNetworkBrowserItem *browserItem = static_cast<Smb4KNetworkBrowserItem *>(items.first()); 0435 0436 if (browserItem) 0437 { 0438 switch (browserItem->type()) 0439 { 0440 case Host: 0441 { 0442 // 0443 // Adjust the actions 0444 // 0445 qobject_cast<KDualAction *>(m_actionCollection->action("rescan_abort_action"))->setInactiveText(i18n("Scan Compute&r")); 0446 m_actionCollection->action("bookmark_action")->setEnabled(false); 0447 m_actionCollection->action("authentication_action")->setEnabled(true); 0448 m_actionCollection->action("custom_action")->setEnabled(true); 0449 m_actionCollection->action("preview_action")->setEnabled(false); 0450 m_actionCollection->action("print_action")->setEnabled(false); 0451 static_cast<KDualAction *>(m_actionCollection->action("mount_action"))->setActive(true); 0452 m_actionCollection->action("mount_action")->setEnabled(false); 0453 break; 0454 } 0455 case Share: 0456 { 0457 // 0458 // Adjust the actions 0459 // 0460 qobject_cast<KDualAction *>(m_actionCollection->action("rescan_abort_action"))->setInactiveText(i18n("Scan Compute&r")); 0461 m_actionCollection->action("bookmark_action")->setEnabled(!browserItem->shareItem()->isPrinter()); 0462 m_actionCollection->action("authentication_action")->setEnabled(true); 0463 m_actionCollection->action("custom_action")->setEnabled(!browserItem->shareItem()->isPrinter()); 0464 m_actionCollection->action("preview_action")->setEnabled(!browserItem->shareItem()->isPrinter()); 0465 m_actionCollection->action("print_action")->setEnabled(browserItem->shareItem()->isPrinter()); 0466 0467 if (!browserItem->shareItem()->isPrinter()) 0468 { 0469 if (!browserItem->shareItem()->isMounted() || (browserItem->shareItem()->isMounted() && browserItem->shareItem()->isForeign())) 0470 { 0471 static_cast<KDualAction *>(m_actionCollection->action("mount_action"))->setActive(true); 0472 m_actionCollection->action("mount_action")->setEnabled(true); 0473 } 0474 else if (browserItem->shareItem()->isMounted() && !browserItem->shareItem()->isForeign()) 0475 { 0476 static_cast<KDualAction *>(m_actionCollection->action("mount_action"))->setActive(false); 0477 m_actionCollection->action("mount_action")->setEnabled(true); 0478 } 0479 else 0480 { 0481 static_cast<KDualAction *>(m_actionCollection->action("mount_action"))->setActive(true); 0482 m_actionCollection->action("mount_action")->setEnabled(false); 0483 } 0484 } 0485 else 0486 { 0487 static_cast<KDualAction *>(m_actionCollection->action("mount_action"))->setActive(true); 0488 m_actionCollection->action("mount_action")->setEnabled(true); 0489 } 0490 break; 0491 } 0492 default: 0493 { 0494 // 0495 // Adjust the actions 0496 // 0497 qobject_cast<KDualAction *>(m_actionCollection->action("rescan_abort_action"))->setInactiveText(i18n("Scan Wo&rkgroup")); 0498 m_actionCollection->action("bookmark_action")->setEnabled(false); 0499 m_actionCollection->action("authentication_action")->setEnabled(false); 0500 m_actionCollection->action("custom_action")->setEnabled(false); 0501 m_actionCollection->action("preview_action")->setEnabled(false); 0502 m_actionCollection->action("print_action")->setEnabled(false); 0503 static_cast<KDualAction *>(m_actionCollection->action("mount_action"))->setActive(true); 0504 m_actionCollection->action("mount_action")->setEnabled(false); 0505 break; 0506 } 0507 } 0508 } 0509 } 0510 else if (items.size() > 1) 0511 { 0512 // 0513 // In this case there are only shares selected, because all other items 0514 // are automatically deselected in extended selection mode. 0515 // 0516 // For deciding which function the mount action should have, we use 0517 // the number of unmounted shares. If that is identical with the items.size(), 0518 // it will mount the items, otherwise it will unmount them. 0519 // 0520 int unmountedShares = items.size(); 0521 0522 for (QTreeWidgetItem *item : items) 0523 { 0524 Smb4KNetworkBrowserItem *browserItem = static_cast<Smb4KNetworkBrowserItem *>(item); 0525 0526 if (browserItem && browserItem->shareItem()->isMounted() && !browserItem->shareItem()->isForeign()) 0527 { 0528 // 0529 // Subtract shares mounted by the user 0530 // 0531 unmountedShares--; 0532 } 0533 } 0534 0535 // 0536 // Adjust the actions 0537 // 0538 qobject_cast<KDualAction *>(m_actionCollection->action("rescan_abort_action"))->setInactiveText(i18n("Scan Netwo&rk")); 0539 m_actionCollection->action("bookmark_action")->setEnabled(true); 0540 m_actionCollection->action("authentication_action")->setEnabled(false); 0541 m_actionCollection->action("custom_action")->setEnabled(false); 0542 m_actionCollection->action("preview_action")->setEnabled(true); 0543 m_actionCollection->action("print_action")->setEnabled(false); 0544 static_cast<KDualAction *>(m_actionCollection->action("mount_action"))->setActive(unmountedShares == items.size()); 0545 m_actionCollection->action("mount_action")->setEnabled(true); 0546 } 0547 else 0548 { 0549 // 0550 // Adjust the actions 0551 // 0552 qobject_cast<KDualAction *>(m_actionCollection->action("rescan_abort_action"))->setInactiveText(i18n("Scan Netwo&rk")); 0553 m_actionCollection->action("bookmark_action")->setEnabled(false); 0554 m_actionCollection->action("authentication_action")->setEnabled(false); 0555 m_actionCollection->action("custom_action")->setEnabled(false); 0556 m_actionCollection->action("preview_action")->setEnabled(false); 0557 m_actionCollection->action("print_action")->setEnabled(false); 0558 static_cast<KDualAction *>(m_actionCollection->action("mount_action"))->setActive(true); 0559 m_actionCollection->action("mount_action")->setEnabled(false); 0560 } 0561 } 0562 0563 0564 void Smb4KNetworkBrowserDockWidget::slotClientAboutToStart(const NetworkItemPtr& /*item*/, int process) 0565 { 0566 // 0567 // Get the rescan/abort action 0568 // 0569 KDualAction *rescanAbortAction = static_cast<KDualAction *>(m_actionCollection->action("rescan_abort_action")); 0570 0571 // 0572 // Make adjustments 0573 // 0574 if (rescanAbortAction) 0575 { 0576 rescanAbortAction->setActive(true); 0577 m_actionCollection->setDefaultShortcut(rescanAbortAction, QKeySequence::Cancel); 0578 } 0579 0580 // 0581 // Set the active status of the search tool bar 0582 // 0583 if (process == NetworkSearch) 0584 { 0585 m_searchToolBar->setActiveState(true); 0586 } 0587 } 0588 0589 0590 void Smb4KNetworkBrowserDockWidget::slotClientFinished(const NetworkItemPtr& /*item*/, int process) 0591 { 0592 // 0593 // Get the rescan/abort action 0594 // 0595 KDualAction *rescanAbortAction = static_cast<KDualAction *>(m_actionCollection->action("rescan_abort_action")); 0596 0597 // 0598 // Make adjustments 0599 // 0600 if (rescanAbortAction) 0601 { 0602 rescanAbortAction->setActive(false); 0603 m_actionCollection->setDefaultShortcut(rescanAbortAction, QKeySequence::Refresh); 0604 } 0605 0606 // 0607 // Set the active status of the search tool bar 0608 // 0609 if (process == NetworkSearch) 0610 { 0611 m_searchToolBar->setActiveState(false); 0612 } 0613 } 0614 0615 0616 void Smb4KNetworkBrowserDockWidget::slotWorkgroups() 0617 { 0618 // 0619 // Process the global workgroup list 0620 // 0621 if (!workgroupsList().isEmpty()) 0622 { 0623 // 0624 // Remove obsolete workgroups and update existing ones 0625 // 0626 QTreeWidgetItemIterator itemIt(m_networkBrowser, QTreeWidgetItemIterator::All); 0627 0628 while (*itemIt) 0629 { 0630 Smb4KNetworkBrowserItem *networkItem = static_cast<Smb4KNetworkBrowserItem *>(*itemIt); 0631 0632 if (networkItem->type() == Workgroup) 0633 { 0634 WorkgroupPtr workgroup = findWorkgroup(networkItem->workgroupItem()->workgroupName()); 0635 0636 if (workgroup) 0637 { 0638 networkItem->update(); 0639 0640 // Update the master browser 0641 for (int i = 0; i < networkItem->childCount(); ++i) 0642 { 0643 Smb4KNetworkBrowserItem *host = static_cast<Smb4KNetworkBrowserItem *>(networkItem->child(i)); 0644 host->update(); 0645 } 0646 } 0647 else 0648 { 0649 delete networkItem; 0650 } 0651 } 0652 0653 ++itemIt; 0654 } 0655 0656 // 0657 // Add new workgroups to the tree widget 0658 // 0659 for (const WorkgroupPtr &workgroup : workgroupsList()) 0660 { 0661 QList<QTreeWidgetItem *> items = m_networkBrowser->findItems(workgroup->workgroupName(), Qt::MatchFixedString, Smb4KNetworkBrowser::Network); 0662 0663 if (items.isEmpty()) 0664 { 0665 (void) new Smb4KNetworkBrowserItem(m_networkBrowser, workgroup); 0666 } 0667 } 0668 0669 // 0670 // Sort the items 0671 // 0672 m_networkBrowser->sortItems(Smb4KNetworkBrowser::Network, Qt::AscendingOrder); 0673 } 0674 else 0675 { 0676 // 0677 // Clear the tree widget 0678 // 0679 m_networkBrowser->clear(); 0680 } 0681 } 0682 0683 0684 void Smb4KNetworkBrowserDockWidget::slotWorkgroupMembers(const WorkgroupPtr& workgroup) 0685 { 0686 // 0687 // Process the list of domain members 0688 // 0689 if (workgroup) 0690 { 0691 // 0692 // Find the workgroup(s) 0693 // 0694 QList<QTreeWidgetItem *> workgroups = m_networkBrowser->findItems(workgroup->workgroupName(), Qt::MatchFixedString, Smb4KNetworkBrowser::Network); 0695 QMutableListIterator<QTreeWidgetItem *> it(workgroups); 0696 0697 while (it.hasNext()) 0698 { 0699 QTreeWidgetItem *item = it.next(); 0700 0701 if (item->type() == Workgroup) 0702 { 0703 Smb4KNetworkBrowserItem *workgroupItem = static_cast<Smb4KNetworkBrowserItem *>(item); 0704 QTreeWidgetItemIterator itemIt(workgroupItem); 0705 0706 // 0707 // Remove obsolete hosts and update existing ones 0708 // 0709 while (*itemIt) 0710 { 0711 Smb4KNetworkBrowserItem *networkItem = static_cast<Smb4KNetworkBrowserItem *>(*itemIt); 0712 0713 if (networkItem->type() == Host) 0714 { 0715 HostPtr host = findHost(networkItem->hostItem()->hostName(), networkItem->hostItem()->workgroupName()); 0716 0717 if (host) 0718 { 0719 networkItem->update(); 0720 } 0721 else 0722 { 0723 delete networkItem; 0724 } 0725 } 0726 else 0727 { 0728 break; 0729 } 0730 0731 ++itemIt; 0732 } 0733 0734 // 0735 // Add new hosts to the workgroup item and remove obsolete workgroups if 0736 // necessary. Honor the auto-expand feature. 0737 // 0738 QList<HostPtr> members = workgroupMembers(workgroupItem->workgroupItem()); 0739 0740 if (!members.isEmpty()) 0741 { 0742 for (const HostPtr &host : members) 0743 { 0744 bool foundHost = false; 0745 0746 for (int i = 0; i < workgroupItem->childCount(); ++i) 0747 { 0748 Smb4KNetworkBrowserItem *hostItem = static_cast<Smb4KNetworkBrowserItem *>(workgroupItem->child(i)); 0749 0750 if (hostItem->hostItem()->hostName() == host->hostName()) 0751 { 0752 foundHost = true; 0753 break; 0754 } 0755 else 0756 { 0757 continue; 0758 } 0759 } 0760 0761 if (!foundHost) 0762 { 0763 (void) new Smb4KNetworkBrowserItem(workgroupItem, host); 0764 } 0765 } 0766 0767 // Auto-expand the workgroup item, if applicable 0768 if (Smb4KSettings::autoExpandNetworkItems() && !workgroupItem->isExpanded() && !m_searchRunning) 0769 { 0770 m_networkBrowser->expandItem(workgroupItem); 0771 } 0772 } 0773 else 0774 { 0775 // Delete all hosts of the workgroup (if there should still be some) and 0776 // remove the workgroup item from the view (no hosts => no workgroup) 0777 while (workgroupItem->childCount() != 0) 0778 { 0779 delete workgroupItem->takeChild(0); 0780 } 0781 0782 delete workgroupItem; 0783 } 0784 } 0785 } 0786 0787 // 0788 // Sort the items 0789 // 0790 m_networkBrowser->sortItems(Smb4KNetworkBrowser::Network, Qt::AscendingOrder); 0791 } 0792 } 0793 0794 0795 void Smb4KNetworkBrowserDockWidget::slotShares(const HostPtr& host) 0796 { 0797 // 0798 // Process the list of shares 0799 // 0800 if (host) 0801 { 0802 // 0803 // Find the host(s) 0804 // 0805 QList<QTreeWidgetItem *> hosts = m_networkBrowser->findItems(host->hostName(), Qt::MatchFixedString|Qt::MatchRecursive, Smb4KNetworkBrowser::Network); 0806 QMutableListIterator<QTreeWidgetItem *> it(hosts); 0807 0808 while (it.hasNext()) 0809 { 0810 Smb4KNetworkBrowserItem *hostItem = static_cast<Smb4KNetworkBrowserItem *>(it.next()); 0811 0812 if (hostItem->type() == Host && hostItem->hostItem()->workgroupName() == host->workgroupName()) 0813 { 0814 QTreeWidgetItemIterator itemIt(hostItem); 0815 0816 // 0817 // Remove obsolete shares and update existing ones 0818 // 0819 while (*itemIt) 0820 { 0821 Smb4KNetworkBrowserItem *shareItem = static_cast<Smb4KNetworkBrowserItem *>(*itemIt); 0822 0823 if (shareItem->type() == Share) 0824 { 0825 SharePtr share = findShare(shareItem->shareItem()->url(), shareItem->shareItem()->workgroupName()); 0826 0827 if (share) 0828 { 0829 shareItem->update(); 0830 } 0831 else 0832 { 0833 delete shareItem; 0834 } 0835 } 0836 else 0837 { 0838 break; 0839 } 0840 0841 ++itemIt; 0842 } 0843 0844 // 0845 // Add new shares to the host item. The host will not be removed from the 0846 // view when it has no shares. Honor the auto-expand feature. 0847 // 0848 QList<SharePtr> shares = sharedResources(host); 0849 0850 if (!shares.isEmpty()) 0851 { 0852 for (const SharePtr &share : shares) 0853 { 0854 bool foundShare = false; 0855 0856 for (int i = 0; i < hostItem->childCount(); ++i) 0857 { 0858 Smb4KNetworkBrowserItem *shareItem = static_cast<Smb4KNetworkBrowserItem *>(hostItem->child(i)); 0859 0860 if (QString::compare(shareItem->shareItem()->url().toString(QUrl::RemoveUserInfo|QUrl::RemovePort), 0861 share->url().toString(QUrl::RemoveUserInfo|QUrl::RemovePort), 0862 Qt::CaseInsensitive) == 0) 0863 { 0864 foundShare = true; 0865 break; 0866 } 0867 else 0868 { 0869 continue; 0870 } 0871 } 0872 0873 if (!foundShare) 0874 { 0875 (void) new Smb4KNetworkBrowserItem(hostItem, share); 0876 } 0877 } 0878 0879 // Auto-expand the host item, if applicable 0880 if (Smb4KSettings::autoExpandNetworkItems() && !hostItem->isExpanded() && !m_searchRunning) 0881 { 0882 m_networkBrowser->expandItem(hostItem); 0883 } 0884 } 0885 else 0886 { 0887 // Delete all shares (if there should still be some), but leave the 0888 // host in the view. 0889 while (hostItem->childCount() != 0) 0890 { 0891 delete hostItem->takeChild(0); 0892 } 0893 } 0894 } 0895 else 0896 { 0897 continue; 0898 } 0899 } 0900 0901 // 0902 // Sort the items 0903 // 0904 m_networkBrowser->sortItems(Smb4KNetworkBrowser::Network, Qt::AscendingOrder); 0905 } 0906 } 0907 0908 0909 void Smb4KNetworkBrowserDockWidget::slotRescanAbortActionTriggered(bool /*checked*/) 0910 { 0911 // 0912 // Get the Rescan/Abort action 0913 // 0914 KDualAction *rescanAbortAction = static_cast<KDualAction *>(m_actionCollection->action("rescan_abort_action")); 0915 0916 0917 // 0918 // Get the selected items 0919 // 0920 QList<QTreeWidgetItem *> selectedItems = m_networkBrowser->selectedItems(); 0921 0922 // 0923 // Perform actions according to the state of the action and the number of 0924 // selected items. 0925 // 0926 if (!rescanAbortAction->isActive()) 0927 { 0928 if (selectedItems.size() == 1) 0929 { 0930 Smb4KNetworkBrowserItem *browserItem = static_cast<Smb4KNetworkBrowserItem *>(selectedItems.first()); 0931 0932 if (browserItem) 0933 { 0934 switch (browserItem->type()) 0935 { 0936 case Workgroup: 0937 { 0938 Smb4KClient::self()->lookupDomainMembers(browserItem->workgroupItem()); 0939 break; 0940 } 0941 case Host: 0942 { 0943 Smb4KClient::self()->lookupShares(browserItem->hostItem()); 0944 break; 0945 } 0946 case Share: 0947 { 0948 Smb4KNetworkBrowserItem *parentItem = static_cast<Smb4KNetworkBrowserItem *>(browserItem->parent()); 0949 Smb4KClient::self()->lookupShares(parentItem->hostItem()); 0950 break; 0951 } 0952 default: 0953 { 0954 break; 0955 } 0956 } 0957 } 0958 } 0959 else 0960 { 0961 // If several items are selected or no selected items, 0962 // only the network can be scanned. 0963 Smb4KClient::self()->lookupDomains(); 0964 } 0965 } 0966 else 0967 { 0968 // Stop all actions performed by the client 0969 if (Smb4KClient::self()->isRunning()) 0970 { 0971 Smb4KClient::self()->abort(); 0972 } 0973 } 0974 } 0975 0976 0977 void Smb4KNetworkBrowserDockWidget::slotAddBookmark(bool /*checked*/) 0978 { 0979 QList<QTreeWidgetItem *> items = m_networkBrowser->selectedItems(); 0980 QList<SharePtr> shares; 0981 0982 if (!items.isEmpty()) 0983 { 0984 for (int i = 0; i < items.size(); ++i) 0985 { 0986 Smb4KNetworkBrowserItem *item = static_cast<Smb4KNetworkBrowserItem *>(items.at(i)); 0987 0988 if (item && item->type() == Share && !item->shareItem()->isPrinter()) 0989 { 0990 shares << item->shareItem(); 0991 } 0992 } 0993 } 0994 else 0995 { 0996 // No selected items. Just return. 0997 return; 0998 } 0999 1000 if (!shares.isEmpty()) 1001 { 1002 Smb4KBookmarkHandler::self()->addBookmarks(shares); 1003 } 1004 } 1005 1006 1007 void Smb4KNetworkBrowserDockWidget::slotMountManually(bool /*checked*/) 1008 { 1009 Smb4KMounter::self()->openMountDialog(); 1010 } 1011 1012 1013 void Smb4KNetworkBrowserDockWidget::slotAuthentication(bool /*checked*/) 1014 { 1015 Smb4KNetworkBrowserItem *item = static_cast<Smb4KNetworkBrowserItem *>(m_networkBrowser->currentItem()); 1016 1017 if (item) 1018 { 1019 switch (item->type()) 1020 { 1021 case Host: 1022 { 1023 Smb4KWalletManager::self()->showPasswordDialog(item->hostItem()); 1024 break; 1025 } 1026 case Share: 1027 { 1028 Smb4KWalletManager::self()->showPasswordDialog(item->shareItem()); 1029 break; 1030 } 1031 default: 1032 { 1033 break; 1034 } 1035 } 1036 } 1037 } 1038 1039 1040 void Smb4KNetworkBrowserDockWidget::slotCustomOptions(bool /*checked*/) 1041 { 1042 Smb4KNetworkBrowserItem *item = static_cast<Smb4KNetworkBrowserItem *>(m_networkBrowser->currentItem()); 1043 1044 if (item) 1045 { 1046 switch (item->type()) 1047 { 1048 case Host: 1049 { 1050 Smb4KCustomOptionsManager::self()->openCustomOptionsDialog(item->hostItem()); 1051 break; 1052 } 1053 case Share: 1054 { 1055 Smb4KCustomOptionsManager::self()->openCustomOptionsDialog(item->shareItem()); 1056 break; 1057 } 1058 default: 1059 { 1060 break; 1061 } 1062 } 1063 } 1064 } 1065 1066 1067 void Smb4KNetworkBrowserDockWidget::slotPreview(bool /*checked*/) 1068 { 1069 QList<QTreeWidgetItem *> items = m_networkBrowser->selectedItems(); 1070 1071 if (!items.isEmpty()) 1072 { 1073 for (int i = 0; i < items.size(); ++i) 1074 { 1075 Smb4KNetworkBrowserItem *item = static_cast<Smb4KNetworkBrowserItem *>(items.at(i)); 1076 1077 if (item && item->type() == Share && !item->shareItem()->isPrinter()) 1078 { 1079 Smb4KClient::self()->openPreviewDialog(item->shareItem()); 1080 } 1081 } 1082 } 1083 } 1084 1085 1086 void Smb4KNetworkBrowserDockWidget::slotPrint(bool /*checked*/) 1087 { 1088 Smb4KNetworkBrowserItem *item = static_cast<Smb4KNetworkBrowserItem *>(m_networkBrowser->currentItem()); 1089 1090 if (item && item->shareItem()->isPrinter()) 1091 { 1092 Smb4KClient::self()->openPrintDialog(item->shareItem()); 1093 } 1094 } 1095 1096 1097 void Smb4KNetworkBrowserDockWidget::slotMountActionTriggered(bool /*checked*/) 1098 { 1099 // 1100 // Get the selected items 1101 // 1102 QList<QTreeWidgetItem *> selectedItems = m_networkBrowser->selectedItems(); 1103 1104 if (selectedItems.size() > 1) 1105 { 1106 // 1107 // In the case of multiple selected network items, selectedItems() 1108 // only contains shares. Thus, we do not need to test for the type. 1109 // For deciding what the mount action is supposed to do, i.e. mount 1110 // the (remaining) selected unmounted shares or unmounting all selected 1111 // mounted shares, we use the number of unmounted shares. If that is 1112 // greater than 0, we mount all shares that need to be mounted, otherwise 1113 // we unmount all selected shares. 1114 // 1115 QList<SharePtr> unmounted, mounted; 1116 1117 for (QTreeWidgetItem *item : selectedItems) 1118 { 1119 Smb4KNetworkBrowserItem *browserItem = static_cast<Smb4KNetworkBrowserItem *>(item); 1120 1121 if (browserItem && browserItem->shareItem()->isMounted()) 1122 { 1123 mounted << browserItem->shareItem(); 1124 } 1125 else if (browserItem && !browserItem->shareItem()->isMounted()) 1126 { 1127 unmounted << browserItem->shareItem(); 1128 } 1129 } 1130 1131 if (!unmounted.empty()) 1132 { 1133 // Mount the (remaining) unmounted shares. 1134 Smb4KMounter::self()->mountShares(unmounted); 1135 } 1136 else 1137 { 1138 // Unmount all shares. 1139 Smb4KMounter::self()->unmountShares(mounted, m_networkBrowser); 1140 } 1141 } 1142 else 1143 { 1144 // 1145 // If only one network item is selected, we need to test for the type 1146 // of the item. Only in case of a share we need to do something. 1147 // 1148 Smb4KNetworkBrowserItem *browserItem = static_cast<Smb4KNetworkBrowserItem *>(selectedItems.first()); 1149 1150 if (browserItem) 1151 { 1152 switch (browserItem->type()) 1153 { 1154 case Share: 1155 { 1156 if (!browserItem->shareItem()->isMounted()) 1157 { 1158 Smb4KMounter::self()->mountShare(browserItem->shareItem()); 1159 } 1160 else 1161 { 1162 Smb4KMounter::self()->unmountShare(browserItem->shareItem(), false); 1163 } 1164 break; 1165 } 1166 default: 1167 { 1168 break; 1169 } 1170 } 1171 } 1172 } 1173 } 1174 1175 1176 void Smb4KNetworkBrowserDockWidget::slotMountActionChanged(bool active) 1177 { 1178 // 1179 // Get the mount action 1180 // 1181 KDualAction *mountAction = static_cast<KDualAction *>(m_actionCollection->action("mount_action")); 1182 1183 // 1184 // Change the shortcuts depending on the value of the 'active' argument 1185 // 1186 if (mountAction) 1187 { 1188 if (active) 1189 { 1190 m_actionCollection->setDefaultShortcut(mountAction, QKeySequence(Qt::CTRL+Qt::Key_M)); 1191 } 1192 else 1193 { 1194 m_actionCollection->setDefaultShortcut(mountAction, QKeySequence(Qt::CTRL+Qt::Key_U)); 1195 } 1196 } 1197 } 1198 1199 1200 void Smb4KNetworkBrowserDockWidget::slotShareMounted(const SharePtr& share) 1201 { 1202 QTreeWidgetItemIterator it(m_networkBrowser); 1203 1204 while (*it) 1205 { 1206 Smb4KNetworkBrowserItem *item = static_cast<Smb4KNetworkBrowserItem *>(*it); 1207 1208 if (item->type() == Share) 1209 { 1210 if (QString::compare(item->shareItem()->url().toString(QUrl::RemoveUserInfo|QUrl::RemovePort), 1211 share->url().toString(QUrl::RemoveUserInfo|QUrl::RemovePort), 1212 Qt::CaseInsensitive) == 0) 1213 { 1214 item->update(); 1215 break; 1216 } 1217 } 1218 1219 ++it; 1220 } 1221 } 1222 1223 1224 void Smb4KNetworkBrowserDockWidget::slotShareUnmounted(const SharePtr& share) 1225 { 1226 QTreeWidgetItemIterator it(m_networkBrowser); 1227 1228 while (*it) 1229 { 1230 Smb4KNetworkBrowserItem *item = static_cast<Smb4KNetworkBrowserItem *>(*it); 1231 1232 if (item->type() == Share) 1233 { 1234 if (QString::compare(item->shareItem()->url().toString(QUrl::RemoveUserInfo|QUrl::RemovePort), 1235 share->url().toString(QUrl::RemoveUserInfo|QUrl::RemovePort), 1236 Qt::CaseInsensitive) == 0) 1237 { 1238 item->update(); 1239 break; 1240 } 1241 } 1242 1243 ++it; 1244 } 1245 } 1246 1247 1248 void Smb4KNetworkBrowserDockWidget::slotMounterAboutToStart(int /*process*/) 1249 { 1250 // 1251 // Unused at the moment 1252 // 1253 } 1254 1255 1256 void Smb4KNetworkBrowserDockWidget::slotMounterFinished(int process) 1257 { 1258 // 1259 // Get the mount/unmount action 1260 // 1261 KDualAction *mountAction = static_cast<KDualAction *>(m_actionCollection->action("mount_action")); 1262 1263 // 1264 // Make adjustments 1265 // 1266 if (mountAction) 1267 { 1268 switch (process) 1269 { 1270 case MountShare: 1271 { 1272 mountAction->setActive(false); 1273 break; 1274 } 1275 case UnmountShare: 1276 { 1277 mountAction->setActive(true); 1278 break; 1279 } 1280 default: 1281 { 1282 break; 1283 } 1284 } 1285 } 1286 } 1287 1288 1289 void Smb4KNetworkBrowserDockWidget::slotIconSizeChanged(int group) 1290 { 1291 switch (group) 1292 { 1293 case KIconLoader::Small: 1294 { 1295 int icon_size = KIconLoader::global()->currentSize(KIconLoader::Small); 1296 m_networkBrowser->setIconSize(QSize(icon_size, icon_size)); 1297 break; 1298 } 1299 default: 1300 { 1301 break; 1302 } 1303 } 1304 } 1305 1306 1307 void Smb4KNetworkBrowserDockWidget::slotShowSearchToolBar() 1308 { 1309 // 1310 // Show the search toolbar 1311 // 1312 m_searchToolBar->setVisible(true); 1313 1314 // 1315 // Set the focus to the search item input 1316 // 1317 m_searchToolBar->prepareInput(); 1318 } 1319 1320 1321 1322 void Smb4KNetworkBrowserDockWidget::slotHideSearchToolBar() 1323 { 1324 // 1325 // Prevent another dock widget from stealing the focus when 1326 // the search tool bar is hidden 1327 // 1328 m_networkBrowser->setFocus(); 1329 1330 // 1331 // Hide the search toolbar 1332 // 1333 m_searchToolBar->setVisible(false); 1334 } 1335 1336 1337 void Smb4KNetworkBrowserDockWidget::slotPerformSearch(const QString& item) 1338 { 1339 // 1340 // Prevent another dock widget from stealing the focus when 1341 // the search item input is disabled 1342 // 1343 m_networkBrowser->setFocus(); 1344 1345 // 1346 // A global search is underway 1347 // 1348 m_searchRunning = true; 1349 1350 // 1351 // Start the search 1352 // 1353 Smb4KClient::self()->search(item); 1354 } 1355 1356 1357 void Smb4KNetworkBrowserDockWidget::slotStopSearch() 1358 { 1359 // 1360 // Stop the network search 1361 // 1362 Smb4KClient::self()->abort(); 1363 1364 // 1365 // A global search finished 1366 // 1367 m_searchRunning = false; 1368 } 1369 1370 1371 void Smb4KNetworkBrowserDockWidget::slotSearchResults(const QList<SharePtr>& shares) 1372 { 1373 // 1374 // A global search finished 1375 // 1376 m_searchRunning = false; 1377 1378 // 1379 // Process the search results 1380 // 1381 QTreeWidgetItemIterator it(m_networkBrowser); 1382 1383 while (*it) 1384 { 1385 Smb4KNetworkBrowserItem *networkItem = static_cast<Smb4KNetworkBrowserItem *>(*it); 1386 1387 if (networkItem->type() == Share) 1388 { 1389 for (const SharePtr &share : shares) 1390 { 1391 if (networkItem->shareItem() == share) 1392 { 1393 // 1394 // Select the search result 1395 // 1396 networkItem->setSelected(true); 1397 1398 // 1399 // Expand the branch of the network tree where a search result 1400 // was retrieved 1401 // 1402 if (!networkItem->parent()->isExpanded()) 1403 { 1404 m_networkBrowser->expandItem(networkItem->parent()); 1405 } 1406 1407 if (!networkItem->parent()->parent()->isExpanded()) 1408 { 1409 m_networkBrowser->expandItem(networkItem->parent()->parent()); 1410 } 1411 } 1412 } 1413 } 1414 1415 it++; 1416 } 1417 1418 // 1419 // Pass the search results to the search toolbar 1420 // 1421 m_searchToolBar->setSearchResults(shares); 1422 } 1423 1424 1425 void Smb4KNetworkBrowserDockWidget::slotJumpToResult(const QString& url) 1426 { 1427 // 1428 // Find the share item with URL url 1429 // 1430 QTreeWidgetItemIterator it(m_networkBrowser); 1431 1432 while (*it) 1433 { 1434 Smb4KNetworkBrowserItem *networkItem = static_cast<Smb4KNetworkBrowserItem *>(*it); 1435 1436 if (networkItem->type() == Share && networkItem->shareItem()->url().toString() == url) 1437 { 1438 m_networkBrowser->setCurrentItem(networkItem); 1439 break; 1440 } 1441 1442 it++; 1443 } 1444 } 1445 1446 1447 void Smb4KNetworkBrowserDockWidget::slotClearSearchResults() 1448 { 1449 m_networkBrowser->clearSelection(); 1450 } 1451 1452 1453 1454