File indexing completed on 2024-11-03 07:47:10
0001 /* 0002 smb4ksystemtray - This is the system tray window class of Smb4K. 0003 0004 SPDX-FileCopyrightText: 2007-2024 Alexander Reinholdt <alexander.reinholdt@kdemail.net> 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 // application specific includes 0009 #include "smb4ksystemtray.h" 0010 #include "core/smb4kclient.h" 0011 #include "core/smb4kglobal.h" 0012 #include "core/smb4kmounter.h" 0013 #include "core/smb4kshare.h" 0014 #include "core/smb4kworkgroup.h" 0015 #include "smb4kbookmarkmenu.h" 0016 #include "smb4kprofilesmenu.h" 0017 #include "smb4ksharesmenu.h" 0018 0019 // Qt includes 0020 #include <QDebug> 0021 #include <QMenu> 0022 #include <QPointer> 0023 0024 // KDE specific includes 0025 #include <KAboutData> 0026 #include <KConfigDialog> 0027 #include <KIconLoader> 0028 #include <KLocalizedString> 0029 #include <KPluginFactory> 0030 #include <KPluginMetaData> 0031 #include <KStandardAction> 0032 #include <knotifications_version.h> 0033 0034 using namespace Smb4KGlobal; 0035 0036 Smb4KSystemTray::Smb4KSystemTray(QWidget *parent) 0037 : KStatusNotifierItem(QStringLiteral("org.kde.smb4k.statusnotifieritem"), parent) 0038 { 0039 QString iconName; 0040 0041 if (KIconLoader::global()->hasIcon(QStringLiteral("network-workgroup-symbolic"))) { 0042 iconName = QStringLiteral("network-workgroup-symbolic"); 0043 } else { 0044 iconName = QStringLiteral("network-workgroup"); 0045 } 0046 0047 setIconByName(iconName); 0048 setToolTip(iconName, i18n("Smb4K"), KAboutData::applicationData().shortDescription()); 0049 setStatus(Active); 0050 setCategory(ApplicationStatus); 0051 0052 QAction *mountAction = new QAction(KDE::icon(QStringLiteral("view-form"), QStringList(QStringLiteral("emblem-mounted"))), i18n("&Open Mount Dialog"), this); 0053 connect(mountAction, &QAction::triggered, this, &Smb4KSystemTray::slotMountDialog); 0054 0055 addAction(QStringLiteral("shares_menu"), new Smb4KSharesMenu(this)); 0056 addAction(QStringLiteral("bookmarks_menu"), new Smb4KBookmarkMenu(Smb4KBookmarkMenu::SystemTray, this)); 0057 addAction(QStringLiteral("profiles_menu"), new Smb4KProfilesMenu(this)); 0058 addAction(QStringLiteral("mount_action"), mountAction); 0059 addAction(QStringLiteral("config_action"), KStandardAction::preferences(parent, SLOT(slotConfigDialog()), this)); 0060 0061 contextMenu()->addAction(action(QStringLiteral("shares_menu"))); 0062 contextMenu()->addAction(action(QStringLiteral("bookmarks_menu"))); 0063 contextMenu()->addAction(action(QStringLiteral("profiles_menu"))); 0064 contextMenu()->addSeparator(); 0065 contextMenu()->addAction(action(QStringLiteral("mount_action"))); 0066 contextMenu()->addAction(action(QStringLiteral("config_action"))); 0067 0068 connect(Smb4KMounter::self(), &Smb4KMounter::mountedSharesListChanged, this, &Smb4KSystemTray::slotSetStatus); 0069 connect(Smb4KClient::self(), &Smb4KClient::workgroups, this, &Smb4KSystemTray::slotSetStatus); 0070 } 0071 0072 Smb4KSystemTray::~Smb4KSystemTray() 0073 { 0074 } 0075 0076 void Smb4KSystemTray::loadSettings() 0077 { 0078 Smb4KBookmarkMenu *bookmarkMenu = qobject_cast<Smb4KBookmarkMenu *>(action(QStringLiteral("bookmarks_menu"))); 0079 0080 if (bookmarkMenu) { 0081 bookmarkMenu->refreshMenu(); 0082 } 0083 0084 Smb4KSharesMenu *sharesMenu = qobject_cast<Smb4KSharesMenu *>(action(QStringLiteral("shares_menu"))); 0085 0086 if (sharesMenu) { 0087 sharesMenu->refreshMenu(); 0088 } 0089 0090 Smb4KProfilesMenu *profilesMenu = qobject_cast<Smb4KProfilesMenu *>(action(QStringLiteral("profiles_menu"))); 0091 0092 if (profilesMenu) { 0093 profilesMenu->refreshMenu(); 0094 } 0095 } 0096 0097 ///////////////////////////////////////////////////////////////////////////// 0098 // SLOT IMPLEMENTATIONS 0099 ///////////////////////////////////////////////////////////////////////////// 0100 0101 void Smb4KSystemTray::slotMountDialog() 0102 { 0103 QPointer<Smb4KMountDialog> mountDialog = new Smb4KMountDialog(); 0104 mountDialog->show(); 0105 } 0106 0107 void Smb4KSystemTray::slotSetStatus() 0108 { 0109 if (!mountedSharesList().isEmpty() || !workgroupsList().isEmpty()) { 0110 setStatus(KStatusNotifierItem::Active); 0111 } else { 0112 setStatus(KStatusNotifierItem::Passive); 0113 } 0114 }