hwmanager: rework code for RMB menu. This does not add any new

functionality but allows the future LMB menu to reuse some of the code.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/308/head
Michele Calgaro 1 year ago
parent b1d5dab80d
commit 8c95671998
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -54,7 +54,34 @@
#include "hwdevicetray_configdialog.h" #include "hwdevicetray_configdialog.h"
typedef TQMap<int, TQString> TQStringMap; // Storage Device Action Type
// use 'int' as underlying type to avoid exposing a bunch of unnecessary
// enums/structs in the class header file private methods' signature
namespace SDActions
{
enum Type : int
{
Open = 1,
Mount,
Unmount,
Unlock,
Lock,
Eject,
SafeRemove,
Properties
};
// Allows to use a for loop to iterate over all action types
static const Type All[] = { Open, Mount, Unmount, Unlock, Lock, Eject, SafeRemove, Properties };
}
// Storage Device Action Menu Entry, representing an action
// and the storage device on which to perform it
struct SDActionMenuEntry
{
SDActions::Type actionType;
TQString uuid;
};
struct KnownDiskDeviceInfo struct KnownDiskDeviceInfo
{ {
@ -62,6 +89,7 @@ struct KnownDiskDeviceInfo
TQString node; TQString node;
}; };
class HwDeviceSystemTrayPrivate class HwDeviceSystemTrayPrivate
{ {
public: public:
@ -74,17 +102,15 @@ public:
} }
// Members // Members
KHelpMenu *m_help; TDEAction *m_deviceManagerAction;
TDEAction *m_quitAction;
TDEAction *m_shortcutKeysAction;
KHelpMenu *m_helpMenu;
TDEPopupMenu *m_RMBMenu; TDEPopupMenu *m_RMBMenu;
TQStringMap m_openMenuIndexMap; int m_menuEntryIdx;
TQStringMap m_mountMenuIndexMap; TQMap<int, SDActionMenuEntry> m_actionMenuEntryMap;
TQStringMap m_unmountMenuIndexMap; TQMap<SDActions::Type, TDEActionMenu*> m_RMBActionMap;
TQStringMap m_unlockMenuIndexMap;
TQStringMap m_lockMenuIndexMap;
TQStringMap m_ejectMenuIndexMap;
TQStringMap m_safeRemoveMenuIndexMap;
TQStringMap m_propertiesMenuIndexMap;
TQMap<TQString, KnownDiskDeviceInfo> m_knownDiskDevices; TQMap<TQString, KnownDiskDeviceInfo> m_knownDiskDevices;
@ -99,11 +125,7 @@ HwDeviceSystemTray::HwDeviceSystemTray(TQWidget *parent, const char *name)
d->m_hardwareNotifierContainer = new TDEPassivePopupStackContainer(); d->m_hardwareNotifierContainer = new TDEPassivePopupStackContainer();
connect(d->m_hardwareNotifierContainer, TQT_SIGNAL(popupClicked(KPassivePopup*, TQPoint, TQString)), this, TQT_SLOT(devicePopupClicked(KPassivePopup*, TQPoint, TQString))); connect(d->m_hardwareNotifierContainer, TQT_SIGNAL(popupClicked(KPassivePopup*, TQPoint, TQString)), this, TQT_SLOT(devicePopupClicked(KPassivePopup*, TQPoint, TQString)));
// Create menus InitRMBMenu();
d->m_help = new KHelpMenu(this, TDEGlobal::instance()->aboutData(), false, actionCollection());
d->m_help->menu()->connectItem(KHelpMenu::menuHelpContents, this, TQT_SLOT(slotHelpContents()));
d->m_RMBMenu = contextMenu();
setPixmap(KSystemTray::loadIcon("hwinfo")); setPixmap(KSystemTray::loadIcon("hwinfo"));
setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
@ -120,15 +142,6 @@ HwDeviceSystemTray::HwDeviceSystemTray(TQWidget *parent, const char *name)
connect(kapp, TQT_SIGNAL(settingsChanged(int)), TQT_SLOT(slotSettingsChanged(int))); connect(kapp, TQT_SIGNAL(settingsChanged(int)), TQT_SLOT(slotSettingsChanged(int)));
new TDEActionMenu(i18n("Open"), SmallIcon("window-new", TQIconSet::Automatic), actionCollection(), "open_menu");
new TDEActionMenu(i18n("Mount"), SmallIcon("drive-harddisk-mounted", TQIconSet::Automatic), actionCollection(), "mount_menu");
new TDEActionMenu(i18n("Unmount"), SmallIcon("drive-harddisk-unmounted", TQIconSet::Automatic), actionCollection(), "unmount_menu");
new TDEActionMenu(i18n("Unlock"), SmallIcon("decrypted", TQIconSet::Automatic), actionCollection(), "unlock_menu");
new TDEActionMenu(i18n("Lock"), SmallIcon("encrypted", TQIconSet::Automatic), actionCollection(), "lock_menu");
new TDEActionMenu(i18n("Eject"), SmallIcon("player_eject", TQIconSet::Automatic), actionCollection(), "eject_menu");
new TDEActionMenu(i18n("Safe remove"), SmallIcon("player_safe_removal", TQIconSet::Automatic), actionCollection(), "safe_remove_menu");
new TDEActionMenu(i18n("Properties"), SmallIcon("edit", TQIconSet::Automatic), actionCollection(), "properties_menu");
TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices(); TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
doDiskNotifications(true); doDiskNotifications(true);
connect(hwdevices, TQT_SIGNAL(hardwareAdded(TDEGenericDevice*)), this, TQT_SLOT(deviceAdded(TDEGenericDevice*))); connect(hwdevices, TQT_SIGNAL(hardwareAdded(TDEGenericDevice*)), this, TQT_SLOT(deviceAdded(TDEGenericDevice*)));
@ -139,7 +152,7 @@ HwDeviceSystemTray::HwDeviceSystemTray(TQWidget *parent, const char *name)
HwDeviceSystemTray::~HwDeviceSystemTray() HwDeviceSystemTray::~HwDeviceSystemTray()
{ {
delete d->m_hardwareNotifierContainer; delete d->m_hardwareNotifierContainer;
delete d; delete d;
} }
/*! /*!
@ -250,87 +263,86 @@ void HwDeviceSystemTray::configChanged() {
// //
} }
void HwDeviceSystemTray::InitRMBMenu()
{
d->m_RMBMenu = contextMenu();
// Device actions
d->m_RMBActionMap.insert(SDActions::Open, new TDEActionMenu(i18n("Open"),
SmallIcon("window-new", TQIconSet::Automatic), actionCollection(), "open_menu"));
d->m_RMBActionMap.insert(SDActions::Mount, new TDEActionMenu(i18n("Mount"),
SmallIcon("drive-harddisk-mounted", TQIconSet::Automatic), actionCollection(), "mount_menu"));
d->m_RMBActionMap.insert(SDActions::Unmount, new TDEActionMenu(i18n("Unmount"),
SmallIcon("drive-harddisk-unmounted", TQIconSet::Automatic), actionCollection(), "unmount_menu"));
d->m_RMBActionMap.insert(SDActions::Unlock, new TDEActionMenu(i18n("Unlock"),
SmallIcon("decrypted", TQIconSet::Automatic), actionCollection(), "unlock_menu"));
d->m_RMBActionMap.insert(SDActions::Lock, new TDEActionMenu(i18n("Lock"),
SmallIcon("encrypted", TQIconSet::Automatic), actionCollection(), "lock_menu"));
d->m_RMBActionMap.insert(SDActions::Eject, new TDEActionMenu(i18n("Eject"),
SmallIcon("player_eject", TQIconSet::Automatic), actionCollection(), "eject_menu"));
d->m_RMBActionMap.insert(SDActions::SafeRemove, new TDEActionMenu(i18n("Safe remove"),
SmallIcon("player_safe_removal", TQIconSet::Automatic), actionCollection(), "safe_remove_menu"));
d->m_RMBActionMap.insert(SDActions::Properties, new TDEActionMenu(i18n("Properties"),
SmallIcon("edit", TQIconSet::Automatic), actionCollection(), "properties_menu"));
// Global Configuration
d->m_deviceManagerAction = new TDEAction(i18n("Show Device Manager..."), SmallIconSet("kcmpci"),
TDEShortcut(), this, TQT_SLOT(slotHardwareConfig()), actionCollection());
d->m_shortcutKeysAction = new TDEAction(i18n("Configure Shortcut Keys..."), SmallIconSet("configure"),
TDEShortcut(), this, TQT_SLOT(slotEditShortcutKeys()), actionCollection());
// Help & Quit
d->m_helpMenu = new KHelpMenu(this, TDEGlobal::instance()->aboutData(), false, actionCollection());
d->m_helpMenu->menu()->connectItem(KHelpMenu::menuHelpContents, this, TQT_SLOT(slotHelpContents()));
d->m_quitAction = actionCollection()->action(KStdAction::name(KStdAction::Quit));
}
void HwDeviceSystemTray::AddDeviceToRMBMenu(TDEStorageDevice *sdevice, const int type)
{
TQString friendlyName = !sdevice->diskLabel().isEmpty() ? sdevice->diskLabel() : sdevice->friendlyName();
TQString uuid = !sdevice->diskUUID().isEmpty() ? sdevice->diskUUID() : sdevice->systemPath();
SDActions::Type actionType = (SDActions::Type)type;
TDEActionMenu *actionMenu = d->m_RMBActionMap[actionType];
actionMenu->popupMenu()->insertItem(sdevice->icon(TDEIcon::SizeSmall),
i18n("%1 (%2)").arg(friendlyName, sdevice->deviceNode()), d->m_menuEntryIdx);
actionMenu->popupMenu()->connectItem(d->m_menuEntryIdx, this, TQT_SLOT(slotExecuteDeviceAction(int)));
actionMenu->setEnabled(true);
d->m_actionMenuEntryMap[d->m_menuEntryIdx++] = { actionType, uuid };
}
void HwDeviceSystemTray::contextMenuAboutToShow(TDEPopupMenu *menu) void HwDeviceSystemTray::contextMenuAboutToShow(TDEPopupMenu *menu)
{ {
d->m_RMBMenu = menu;
menu->clear(); menu->clear();
menu->setCheckable(true);
// Device actions for (const SDActions::Type &actionType : SDActions::All)
menu->insertTitle(SmallIcon("drive-harddisk-unmounted"), i18n("Storage Device Actions")); {
TDEActionMenu *actionMenu = d->m_RMBActionMap[actionType];
TDEActionMenu *openDeviceActionMenu = static_cast<TDEActionMenu*>(actionCollection()->action("open_menu")); actionMenu->popupMenu()->clear();
TDEActionMenu *mountDeviceActionMenu = static_cast<TDEActionMenu*>(actionCollection()->action("mount_menu")); actionMenu->setEnabled(false);
TDEActionMenu *unmountDeviceActionMenu = static_cast<TDEActionMenu*>(actionCollection()->action("unmount_menu")); actionMenu->unplug(d->m_RMBMenu);
TDEActionMenu *unlockDeviceActionMenu = static_cast<TDEActionMenu*>(actionCollection()->action("unlock_menu")); }
TDEActionMenu *lockDeviceActionMenu = static_cast<TDEActionMenu*>(actionCollection()->action("lock_menu"));
TDEActionMenu *ejectDeviceActionMenu = static_cast<TDEActionMenu*>(actionCollection()->action("eject_menu"));
TDEActionMenu *safeRemoveDeviceActionMenu = static_cast<TDEActionMenu*>(actionCollection()->action("safe_remove_menu"));
TDEActionMenu *propertiesDeviceActionMenu = static_cast<TDEActionMenu*>(actionCollection()->action("properties_menu"));
openDeviceActionMenu->popupMenu()->clear();
mountDeviceActionMenu->popupMenu()->clear();
unmountDeviceActionMenu->popupMenu()->clear();
unlockDeviceActionMenu->popupMenu()->clear();
lockDeviceActionMenu->popupMenu()->clear();
ejectDeviceActionMenu->popupMenu()->clear();
safeRemoveDeviceActionMenu->popupMenu()->clear();
propertiesDeviceActionMenu->popupMenu()->clear();
d->m_openMenuIndexMap.clear();
d->m_mountMenuIndexMap.clear();
d->m_unmountMenuIndexMap.clear();
d->m_unlockMenuIndexMap.clear();
d->m_lockMenuIndexMap.clear();
d->m_ejectMenuIndexMap.clear();
d->m_safeRemoveMenuIndexMap.clear();
d->m_propertiesMenuIndexMap.clear();
// Find all storage devices and add them to the popup menus d->m_actionMenuEntryMap.clear();
int lastOpenIndex = -1; d->m_menuEntryIdx = 0;
int lastMountIndex = -1;
int lastUnmountIndex = -1;
int lastUnlockIndex = -1;
int lastLockIndex = -1;
int lastEjectIndex = -1;
int lastSafeRemoveIndex = -1;
int lastPropertiesIndex = -1;
// Find all storage devices and add them to the popup menus
TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices(); TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
TDEGenericHardwareList diskDeviceList = hwdevices->listByDeviceClass(TDEGenericDeviceType::Disk); TDEGenericHardwareList diskDeviceList = hwdevices->listByDeviceClass(TDEGenericDeviceType::Disk);
for (TDEGenericDevice *hwdevice = diskDeviceList.first(); hwdevice; hwdevice = diskDeviceList.next()) for (TDEGenericDevice *hwdevice = diskDeviceList.first(); hwdevice; hwdevice = diskDeviceList.next())
{ {
TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(hwdevice); TDEStorageDevice *sdevice = static_cast<TDEStorageDevice*>(hwdevice);
if (isMonitoredDevice(sdevice)) if (isMonitoredDevice(sdevice))
{ {
TQString friendlyName = sdevice->diskLabel();
if (friendlyName.isEmpty())
{
friendlyName = sdevice->friendlyName();
}
if (sdevice->isDiskOfType(TDEDiskDeviceType::LUKS) || sdevice->isDiskOfType(TDEDiskDeviceType::OtherCrypted)) if (sdevice->isDiskOfType(TDEDiskDeviceType::LUKS) || sdevice->isDiskOfType(TDEDiskDeviceType::OtherCrypted))
{ {
if (sdevice->isDiskOfType(TDEDiskDeviceType::UnlockedCrypt)) if (sdevice->isDiskOfType(TDEDiskDeviceType::UnlockedCrypt))
{ {
lastLockIndex = lockDeviceActionMenu->popupMenu()->insertItem(hwdevice->icon(TDEIcon::SizeSmall), AddDeviceToRMBMenu(sdevice, SDActions::Lock);
i18n("%1 (%2)").arg(friendlyName, sdevice->deviceNode()));
lockDeviceActionMenu->popupMenu()->connectItem(lastLockIndex, this, TQT_SLOT(slotLockDevice(int)));
d->m_lockMenuIndexMap[lastLockIndex] = sdevice->diskUUID();
if (d->m_lockMenuIndexMap[lastLockIndex] == "")
{
d->m_lockMenuIndexMap[lastLockIndex] = sdevice->systemPath();
}
} }
else else
{ {
lastUnlockIndex = unlockDeviceActionMenu->popupMenu()->insertItem(hwdevice->icon(TDEIcon::SizeSmall), AddDeviceToRMBMenu(sdevice, SDActions::Unlock);
i18n("%1 (%2)").arg(friendlyName, sdevice->deviceNode()));
unlockDeviceActionMenu->popupMenu()->connectItem(lastUnlockIndex, this, TQT_SLOT(slotUnlockDevice(int)));
d->m_unlockMenuIndexMap[lastUnlockIndex] = sdevice->diskUUID();
if (d->m_unlockMenuIndexMap[lastUnlockIndex] == "")
{
d->m_unlockMenuIndexMap[lastUnlockIndex] = sdevice->systemPath();
}
} }
} }
@ -338,132 +350,57 @@ void HwDeviceSystemTray::contextMenuAboutToShow(TDEPopupMenu *menu)
{ {
if (sdevice->mountPath().isEmpty()) if (sdevice->mountPath().isEmpty())
{ {
lastMountIndex = mountDeviceActionMenu->popupMenu()->insertItem(hwdevice->icon(TDEIcon::SizeSmall), AddDeviceToRMBMenu(sdevice, SDActions::Mount);
i18n("%1 (%2)").arg(friendlyName, sdevice->deviceNode()));
mountDeviceActionMenu->popupMenu()->connectItem(lastMountIndex, this, TQT_SLOT(slotMountDevice(int)));
d->m_mountMenuIndexMap[lastMountIndex] = sdevice->diskUUID();
if (d->m_mountMenuIndexMap[lastMountIndex] == "")
{
d->m_mountMenuIndexMap[lastMountIndex] = sdevice->systemPath();
}
} }
else else
{ {
lastUnmountIndex = unmountDeviceActionMenu->popupMenu()->insertItem(hwdevice->icon(TDEIcon::SizeSmall), AddDeviceToRMBMenu(sdevice, SDActions::Unmount);
i18n("%1 (%2)").arg(friendlyName, sdevice->deviceNode()));
unmountDeviceActionMenu->popupMenu()->connectItem(lastUnmountIndex, this, TQT_SLOT(slotUnmountDevice(int)));
d->m_unmountMenuIndexMap[lastUnmountIndex] = sdevice->diskUUID();
if (d->m_unmountMenuIndexMap[lastMountIndex] == "")
{
d->m_unmountMenuIndexMap[lastMountIndex] = sdevice->systemPath();
}
} }
// Both mounted and unmounted disks can be opened // Mounted and unmounted disks can also be opened
lastOpenIndex = openDeviceActionMenu->popupMenu()->insertItem(hwdevice->icon(TDEIcon::SizeSmall), AddDeviceToRMBMenu(sdevice, SDActions::Open);
i18n("%1 (%2)").arg(friendlyName, sdevice->deviceNode()));
openDeviceActionMenu->popupMenu()->connectItem(lastOpenIndex, this, TQT_SLOT(slotOpenDevice(int)));
d->m_openMenuIndexMap[lastOpenIndex] = sdevice->diskUUID();
if (d->m_openMenuIndexMap[lastOpenIndex] == "")
{
d->m_openMenuIndexMap[lastOpenIndex] = sdevice->systemPath();
}
} }
if (sdevice->checkDiskStatus(TDEDiskDeviceStatus::Removable) || if (sdevice->checkDiskStatus(TDEDiskDeviceStatus::Removable) ||
sdevice->checkDiskStatus(TDEDiskDeviceStatus::Hotpluggable)) sdevice->checkDiskStatus(TDEDiskDeviceStatus::Hotpluggable))
{ {
lastEjectIndex = ejectDeviceActionMenu->popupMenu()->insertItem(hwdevice->icon(TDEIcon::SizeSmall), AddDeviceToRMBMenu(sdevice, SDActions::Eject);
i18n("%1 (%2)").arg(friendlyName, sdevice->deviceNode()));
ejectDeviceActionMenu->popupMenu()->connectItem(lastEjectIndex, this, TQT_SLOT(slotEjectDevice(int)));
d->m_ejectMenuIndexMap[lastEjectIndex] = sdevice->diskUUID();
if (d->m_ejectMenuIndexMap[lastEjectIndex] == "")
{
d->m_ejectMenuIndexMap[lastEjectIndex] = sdevice->systemPath();
}
lastSafeRemoveIndex = safeRemoveDeviceActionMenu->popupMenu()->insertItem(hwdevice->icon(TDEIcon::SizeSmall), AddDeviceToRMBMenu(sdevice, SDActions::SafeRemove);
i18n("%1 (%2)").arg(friendlyName, sdevice->deviceNode()));
safeRemoveDeviceActionMenu->popupMenu()->connectItem(lastSafeRemoveIndex, this, TQT_SLOT(slotSafeRemoveDevice(int)));
d->m_safeRemoveMenuIndexMap[lastSafeRemoveIndex] = sdevice->diskUUID();
if (d->m_safeRemoveMenuIndexMap[lastSafeRemoveIndex] == "")
{
d->m_safeRemoveMenuIndexMap[lastSafeRemoveIndex] = sdevice->systemPath();
}
} }
lastPropertiesIndex = propertiesDeviceActionMenu->popupMenu()->insertItem(hwdevice->icon(TDEIcon::SizeSmall), AddDeviceToRMBMenu(sdevice, SDActions::Properties);
i18n("%1 (%2)").arg(friendlyName, sdevice->deviceNode()));
propertiesDeviceActionMenu->popupMenu()->connectItem(lastPropertiesIndex, this, TQT_SLOT(slotPropertiesDevice(int)));
d->m_propertiesMenuIndexMap[lastPropertiesIndex] = sdevice->diskUUID();
if (d->m_propertiesMenuIndexMap[lastPropertiesIndex] == "")
{
d->m_propertiesMenuIndexMap[lastPropertiesIndex] = sdevice->systemPath();
}
} }
} }
openDeviceActionMenu->setEnabled(lastOpenIndex != -1); // Plug in meaningful action menus
mountDeviceActionMenu->setEnabled(lastMountIndex != -1); d->m_RMBMenu->insertTitle(SmallIcon("drive-harddisk-unmounted"), i18n("Storage Device Actions"), 0);
unmountDeviceActionMenu->setEnabled(lastUnmountIndex != -1); for (const SDActions::Type &actionType : SDActions::All)
unlockDeviceActionMenu->setEnabled(lastUnlockIndex != -1);
lockDeviceActionMenu->setEnabled(lastLockIndex != -1);
ejectDeviceActionMenu->setEnabled(lastEjectIndex != -1);
safeRemoveDeviceActionMenu->setEnabled(lastSafeRemoveIndex != -1);
propertiesDeviceActionMenu->setEnabled(lastPropertiesIndex != -1);
if (lastOpenIndex != -1)
{
openDeviceActionMenu->plug(menu);
}
if (lastMountIndex != -1)
{
mountDeviceActionMenu->plug(menu);
}
if (lastUnmountIndex != -1)
{
unmountDeviceActionMenu->plug(menu);
}
if (lastUnlockIndex != -1)
{ {
unlockDeviceActionMenu->plug(menu); TDEActionMenu *actionMenu = d->m_RMBActionMap[actionType];
} if (actionMenu->isEnabled())
if (lastLockIndex != -1) {
{ actionMenu->plug(d->m_RMBMenu, (int)actionType);
lockDeviceActionMenu->plug(menu); }
}
if (lastEjectIndex != -1)
{
ejectDeviceActionMenu->plug(menu);
}
if (lastSafeRemoveIndex != -1)
{
safeRemoveDeviceActionMenu->plug(menu);
}
if (lastPropertiesIndex != -1)
{
propertiesDeviceActionMenu->plug(menu);
} }
// Global Configuration // Global Configuration
menu->insertTitle(SmallIcon("configure"), i18n("Global Configuration")); menu->insertTitle(SmallIcon("configure"), i18n("Global Configuration"));
TDEAction *actHardwareConfig = new TDEAction(i18n("Show Device Manager..."), SmallIconSet("kcmpci"), TDEShortcut(), this, TQT_SLOT(slotHardwareConfig()), actionCollection()); d->m_deviceManagerAction->plug(menu);
actHardwareConfig->plug(menu); d->m_shortcutKeysAction->plug(menu);
TDEAction *actShortcutKeys = new TDEAction(i18n("Configure Shortcut Keys..."), SmallIconSet("configure"), TDEShortcut(), this, TQT_SLOT(slotEditShortcutKeys()), actionCollection());
actShortcutKeys->plug(menu);
// Help & Quit // Help & Quit
menu->insertSeparator(); menu->insertSeparator();
menu->insertItem(SmallIcon("help"), KStdGuiItem::help().text(), d->m_help->menu()); menu->insertItem(SmallIcon("help"), KStdGuiItem::help().text(), d->m_helpMenu->menu());
TDEAction *quitAction = actionCollection()->action(KStdAction::name(KStdAction::Quit)); d->m_quitAction->plug(menu);
quitAction->plug(menu);
} }
void HwDeviceSystemTray::slotOpenDevice(int parameter) void HwDeviceSystemTray::slotExecuteDeviceAction(int parameter)
{ {
TQString uuid = d->m_openMenuIndexMap[parameter]; TQString uuid = d->m_actionMenuEntryMap[parameter].uuid;
int actionType = d->m_actionMenuEntryMap[parameter].actionType;
if (!uuid.isEmpty()) if (!uuid.isEmpty())
{ {
TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices(); TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
@ -473,189 +410,47 @@ void HwDeviceSystemTray::slotOpenDevice(int parameter)
TDEStorageDevice *sdevice = static_cast<TDEStorageDevice*>(hwdevice); TDEStorageDevice *sdevice = static_cast<TDEStorageDevice*>(hwdevice);
if ((sdevice->diskUUID() == uuid) || (sdevice->systemPath() == uuid)) if ((sdevice->diskUUID() == uuid) || (sdevice->systemPath() == uuid))
{ {
if (sdevice->isDiskOfType(TDEDiskDeviceType::Camera)) if (actionType == SDActions::Open)
{ {
new KRun(TQString("media:/%1").arg(sdevice->friendlyName())); if (sdevice->isDiskOfType(TDEDiskDeviceType::Camera))
}
else
{
new KRun(TQString("system:/media/%1").arg(TQFileInfo(sdevice->deviceNode()).baseName(true)));
}
return;
}
}
}
}
void HwDeviceSystemTray::slotMountDevice(int parameter)
{
TQString uuid = d->m_mountMenuIndexMap[parameter];
if (!uuid.isEmpty())
{
TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
TDEGenericHardwareList diskDeviceList = hwdevices->listByDeviceClass(TDEGenericDeviceType::Disk);
for (TDEGenericDevice *hwdevice = diskDeviceList.first(); hwdevice; hwdevice = diskDeviceList.next())
{
TDEStorageDevice *sdevice = static_cast<TDEStorageDevice*>(hwdevice);
if ((sdevice->diskUUID() == uuid) || (sdevice->systemPath() == uuid))
{
if (sdevice->mountPath().isEmpty())
{
TDEProcess proc;
proc << "tdeio_media_mounthelper" << "-m" << sdevice->deviceNode();
if (!proc.start(TDEProcess::DontCare))
{ {
KMessageBox::error(this, i18n("Could not start tdeio_media_mounthelper process."), new KRun(TQString("media:/%1").arg(sdevice->friendlyName()));
i18n("Device monitor"));
} }
} else
}
}
}
}
void HwDeviceSystemTray::slotUnmountDevice(int parameter)
{
TQString uuid = d->m_unmountMenuIndexMap[parameter];
if (!uuid.isEmpty())
{
TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
TDEGenericHardwareList diskDeviceList = hwdevices->listByDeviceClass(TDEGenericDeviceType::Disk);
for (TDEGenericDevice *hwdevice = diskDeviceList.first(); hwdevice; hwdevice = diskDeviceList.next())
{
TDEStorageDevice *sdevice = static_cast<TDEStorageDevice*>(hwdevice);
if ((sdevice->diskUUID() == uuid) || (sdevice->systemPath() == uuid))
{
if (!sdevice->mountPath().isEmpty())
{
TDEProcess proc;
proc << "tdeio_media_mounthelper" << "-u" << sdevice->deviceNode();
if (!proc.start(TDEProcess::DontCare))
{ {
KMessageBox::error(this, i18n("Could not start tdeio_media_mounthelper process."), new KRun(TQString("system:/media/%1").arg(TQFileInfo(sdevice->deviceNode()).baseName(true)));
i18n("Device monitor"));
} }
} }
} else if (actionType == SDActions::Properties)
}
}
}
void HwDeviceSystemTray::slotUnlockDevice(int parameter)
{
TQString uuid = d->m_unlockMenuIndexMap[parameter];
if (!uuid.isEmpty())
{
TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
TDEGenericHardwareList diskDeviceList = hwdevices->listByDeviceClass(TDEGenericDeviceType::Disk);
for (TDEGenericDevice *hwdevice = diskDeviceList.first(); hwdevice; hwdevice = diskDeviceList.next())
{
TDEStorageDevice *sdevice = static_cast<TDEStorageDevice*>(hwdevice);
if ((sdevice->diskUUID() == uuid) || (sdevice->systemPath() == uuid))
{
TDEProcess proc;
proc << "tdeio_media_mounthelper" << "-k" << sdevice->deviceNode();
if (!proc.start(TDEProcess::DontCare))
{
KMessageBox::error(this, i18n("Could not start tdeio_media_mounthelper process."),
i18n("Device monitor"));
}
}
}
}
}
void HwDeviceSystemTray::slotLockDevice(int parameter)
{
TDEGenericDevice *hwdevice;
TQString uuid = d->m_lockMenuIndexMap[parameter];
if (!uuid.isEmpty())
{
TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
TDEGenericHardwareList diskDeviceList = hwdevices->listByDeviceClass(TDEGenericDeviceType::Disk);
for (hwdevice = diskDeviceList.first(); hwdevice; hwdevice = diskDeviceList.next()) {
TDEStorageDevice *sdevice = static_cast<TDEStorageDevice*>(hwdevice);
if ((sdevice->diskUUID() == uuid) || (sdevice->systemPath() == uuid))
{
TDEProcess proc;
proc << "tdeio_media_mounthelper" << "-l" << sdevice->deviceNode();
if (!proc.start(TDEProcess::DontCare))
{
KMessageBox::error(this, i18n("Could not start tdeio_media_mounthelper process."),
i18n("Device monitor"));
}
}
}
}
}
void HwDeviceSystemTray::slotEjectDevice(int parameter)
{
TQString uuid = d->m_ejectMenuIndexMap[parameter];
if (!uuid.isEmpty())
{
TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
TDEGenericHardwareList diskDeviceList = hwdevices->listByDeviceClass(TDEGenericDeviceType::Disk);
for (TDEGenericDevice *hwdevice = diskDeviceList.first(); hwdevice; hwdevice = diskDeviceList.next())
{
TDEStorageDevice *sdevice = static_cast<TDEStorageDevice*>(hwdevice);
if ((sdevice->diskUUID() == uuid) || (sdevice->systemPath() == uuid))
{
TDEProcess proc;
proc << "tdeio_media_mounthelper" << "-e" << sdevice->deviceNode();
if (!proc.start(TDEProcess::DontCare))
{ {
KMessageBox::error(this, i18n("Could not start tdeio_media_mounthelper process."), new KPropertiesDialog(KURL(TQString("media:/%1").arg(sdevice->deviceNode())));
i18n("Device monitor"));
} }
} else
}
}
}
void HwDeviceSystemTray::slotSafeRemoveDevice(int parameter)
{
TQString uuid = d->m_safeRemoveMenuIndexMap[parameter];
if (!uuid.isEmpty())
{
TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
TDEGenericHardwareList diskDeviceList = hwdevices->listByDeviceClass(TDEGenericDeviceType::Disk);
for (TDEGenericDevice *hwdevice = diskDeviceList.first(); hwdevice; hwdevice = diskDeviceList.next())
{
TDEStorageDevice *sdevice = static_cast<TDEStorageDevice*>(hwdevice);
if ((sdevice->diskUUID() == uuid) || (sdevice->systemPath() == uuid))
{
TDEProcess proc;
proc << "tdeio_media_mounthelper" << "-s" << sdevice->deviceNode();
if (!proc.start(TDEProcess::DontCare))
{ {
KMessageBox::error(this, i18n("Could not start tdeio_media_mounthelper process."), TQString opType = TQString::null;
i18n("Device monitor")); if (actionType == SDActions::Mount) { opType = "-m"; }
else if (actionType == SDActions::Unmount) { opType = "-u"; }
else if (actionType == SDActions::Unlock) { opType = "-k"; }
else if (actionType == SDActions::Lock) { opType = "-l"; }
else if (actionType == SDActions::Eject) { opType = "-e"; }
else if (actionType == SDActions::SafeRemove) { opType = "-s"; }
if (!opType.isEmpty())
{
TDEProcess proc;
proc << "tdeio_media_mounthelper" << opType << sdevice->deviceNode();
if (!proc.start(TDEProcess::DontCare))
{
KMessageBox::error(this, i18n("Could not start tdeio_media_mounthelper process."),
i18n("Device monitor"));
}
}
} }
} }
} }
} }
} }
void HwDeviceSystemTray::slotPropertiesDevice(int parameter)
{
TQString uuid = d->m_propertiesMenuIndexMap[parameter];
if (!uuid.isEmpty())
{
TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
TDEGenericHardwareList diskDeviceList = hwdevices->listByDeviceClass(TDEGenericDeviceType::Disk);
for (TDEGenericDevice *hwdevice = diskDeviceList.first(); hwdevice; hwdevice = diskDeviceList.next())
{
TDEStorageDevice *sdevice = static_cast<TDEStorageDevice*>(hwdevice);
if ((sdevice->diskUUID() == uuid) || (sdevice->systemPath() == uuid))
{
new KPropertiesDialog(KURL(TQString("media:/%1").arg(sdevice->deviceNode())));
return;
}
}
}
}
void HwDeviceSystemTray::slotHardwareConfig() { void HwDeviceSystemTray::slotHardwareConfig() {
KCMultiDialog *kcm = new KCMultiDialog(KDialogBase::Plain, i18n("Configure"), this); KCMultiDialog *kcm = new KCMultiDialog(KDialogBase::Plain, i18n("Configure"), this);

@ -24,12 +24,13 @@
class HwDeviceSystemTrayPrivate; class HwDeviceSystemTrayPrivate;
class KPassivePopup; class KPassivePopup;
class TDEActionMenu;
class TDEGenericDevice; class TDEGenericDevice;
class TDEGlobalAccel; class TDEGlobalAccel;
class TDEPopupMenu; class TDEPopupMenu;
class TDEStorageDevice; class TDEStorageDevice;
class HwDeviceSystemTray : public KSystemTray class HwDeviceSystemTray : public KSystemTray
{ {
Q_OBJECT Q_OBJECT
@ -48,22 +49,8 @@ protected slots:
void slotEditShortcutKeys(); void slotEditShortcutKeys();
void slotSettingsChanged(int category); void slotSettingsChanged(int category);
void slotHelpContents(); void slotHelpContents();
void slotExecuteDeviceAction(int parameter);
void slotOpenDevice(int parameter);
void slotMountDevice(int parameter);
void slotUnmountDevice(int parameter);
void slotUnlockDevice(int parameter);
void slotLockDevice(int parameter);
void slotEjectDevice(int parameter);
void slotSafeRemoveDevice(int parameter);
void slotPropertiesDevice(int parameter);
protected:
void mousePressEvent(TQMouseEvent *e);
void resizeEvent(TQResizeEvent *);
void showEvent(TQShowEvent *);
private slots:
void quitApp(); void quitApp();
void deviceAdded(TDEGenericDevice*); void deviceAdded(TDEGenericDevice*);
void deviceRemoved(TDEGenericDevice*); void deviceRemoved(TDEGenericDevice*);
@ -71,12 +58,18 @@ private slots:
void devicePopupClicked(KPassivePopup*, TQPoint, TQString); void devicePopupClicked(KPassivePopup*, TQPoint, TQString);
void doDiskNotifications(bool scanOnly); void doDiskNotifications(bool scanOnly);
private: protected:
void mousePressEvent(TQMouseEvent *e);
void resizeEvent(TQResizeEvent *);
void resizeTrayIcon();
void showEvent(TQShowEvent *);
static bool isMonitoredDevice(TDEStorageDevice *sdevice); static bool isMonitoredDevice(TDEStorageDevice *sdevice);
void resizeTrayIcon(); void InitRMBMenu();
void AddDeviceToRMBMenu(TDEStorageDevice *sdevice, const int type);
HwDeviceSystemTrayPrivate *d; HwDeviceSystemTrayPrivate *d;
}; };
#endif #endif

Loading…
Cancel
Save