Changeset View
Changeset View
Standalone View
Standalone View
krusader/GUI/mediabutton.cpp
Show All 15 Lines | |||||
16 | * * | 16 | * * | ||
17 | * You should have received a copy of the GNU General Public License * | 17 | * You should have received a copy of the GNU General Public License * | ||
18 | * along with Krusader. If not, see [http://www.gnu.org/licenses/]. * | 18 | * along with Krusader. If not, see [http://www.gnu.org/licenses/]. * | ||
19 | *****************************************************************************/ | 19 | *****************************************************************************/ | ||
20 | 20 | | |||
21 | #include "mediabutton.h" | 21 | #include "mediabutton.h" | ||
22 | 22 | | |||
23 | #include "../krglobal.h" | 23 | #include "../krglobal.h" | ||
24 | #include "../icon.h" | ||||
24 | #include "../MountMan/kmountman.h" | 25 | #include "../MountMan/kmountman.h" | ||
25 | 26 | | |||
26 | // QtCore | 27 | // QtCore | ||
27 | #include <QEvent> | 28 | #include <QEvent> | ||
28 | // QtGui | 29 | // QtGui | ||
29 | #include <QMouseEvent> | 30 | #include <QMouseEvent> | ||
30 | #include <QCursor> | 31 | #include <QCursor> | ||
31 | 32 | | |||
32 | #include <KConfigCore/KConfigGroup> | 33 | #include <KConfigCore/KConfigGroup> | ||
33 | #include <KConfigCore/KSharedConfig> | 34 | #include <KConfigCore/KSharedConfig> | ||
34 | #include <KI18n/KLocalizedString> | 35 | #include <KI18n/KLocalizedString> | ||
35 | #include <KIO/Global> | 36 | #include <KIO/Global> | ||
36 | #include <KIOCore/KMountPoint> | 37 | #include <KIOCore/KMountPoint> | ||
37 | #include <KIconThemes/KIconLoader> | | |||
38 | #include <KWidgetsAddons/KMessageBox> | 38 | #include <KWidgetsAddons/KMessageBox> | ||
39 | 39 | | |||
40 | #include <Solid/DeviceInterface> | 40 | #include <Solid/DeviceInterface> | ||
41 | #include <Solid/StorageAccess> | 41 | #include <Solid/StorageAccess> | ||
42 | #include <Solid/StorageVolume> | 42 | #include <Solid/StorageVolume> | ||
43 | #include <Solid/OpticalDisc> | 43 | #include <Solid/OpticalDisc> | ||
44 | #include <Solid/OpticalDrive> | 44 | #include <Solid/OpticalDrive> | ||
45 | #include <Solid/DeviceNotifier> | 45 | #include <Solid/DeviceNotifier> | ||
46 | 46 | | |||
47 | QString MediaButton::remotePrefix = QLatin1String("remote:"); | 47 | QString MediaButton::remotePrefix = QLatin1String("remote:"); | ||
48 | 48 | | |||
49 | 49 | | |||
50 | MediaButton::MediaButton(QWidget *parent) : QToolButton(parent), | 50 | MediaButton::MediaButton(QWidget *parent) : QToolButton(parent), | ||
51 | popupMenu(0), rightMenu(0), openInNewTab(false) | 51 | popupMenu(0), rightMenu(0), openInNewTab(false) | ||
52 | { | 52 | { | ||
53 | setAutoRaise(true); | 53 | setAutoRaise(true); | ||
54 | setIcon(QIcon::fromTheme("system-file-manager")); | 54 | setIcon(Icon("system-file-manager")); | ||
55 | setText(i18n("Open the available media list")); | 55 | setText(i18n("Open the available media list")); | ||
56 | setToolTip(i18n("Open the available media list")); | 56 | setToolTip(i18n("Open the available media list")); | ||
57 | setPopupMode(QToolButton::InstantPopup); | 57 | setPopupMode(QToolButton::InstantPopup); | ||
58 | setAcceptDrops(false); | 58 | setAcceptDrops(false); | ||
59 | 59 | | |||
60 | popupMenu = new QMenu(this); | 60 | popupMenu = new QMenu(this); | ||
61 | popupMenu->installEventFilter(this); | 61 | popupMenu->installEventFilter(this); | ||
62 | Q_CHECK_PTR(popupMenu); | 62 | Q_CHECK_PTR(popupMenu); | ||
Show All 19 Lines | |||||
82 | 82 | | |||
83 | void MediaButton::updateIcon(const QString &mountPoint) | 83 | void MediaButton::updateIcon(const QString &mountPoint) | ||
84 | { | 84 | { | ||
85 | if(!mountPoint.isEmpty() && mountPoint == currentMountPoint) | 85 | if(!mountPoint.isEmpty() && mountPoint == currentMountPoint) | ||
86 | return; | 86 | return; | ||
87 | 87 | | |||
88 | currentMountPoint = mountPoint; | 88 | currentMountPoint = mountPoint; | ||
89 | 89 | | |||
90 | QString icon("system-file-manager"); | 90 | QString iconName("system-file-manager"); | ||
91 | QStringList overlays; | 91 | QStringList overlays; | ||
92 | 92 | | |||
93 | if(!mountPoint.isEmpty()) { | 93 | if(!mountPoint.isEmpty()) { | ||
94 | Solid::Device device(krMtMan.findUdiForPath(mountPoint, Solid::DeviceInterface::StorageAccess));; | 94 | Solid::Device device(krMtMan.findUdiForPath(mountPoint, Solid::DeviceInterface::StorageAccess));; | ||
95 | Solid::StorageVolume *vol = device.as<Solid::StorageVolume> (); | 95 | Solid::StorageVolume *vol = device.as<Solid::StorageVolume> (); | ||
96 | 96 | | |||
97 | if(device.isValid()) | 97 | if(device.isValid()) | ||
98 | icon = device.icon(); | 98 | iconName = device.icon(); | ||
99 | if (vol && vol->usage() == Solid::StorageVolume::Encrypted) | 99 | if (vol && vol->usage() == Solid::StorageVolume::Encrypted) | ||
100 | overlays << "security-high"; | 100 | overlays << "security-high"; | ||
101 | } | 101 | } | ||
102 | setIcon(KDE::icon(icon, overlays)); | 102 | setIcon(Icon(iconName, overlays)); | ||
103 | } | 103 | } | ||
104 | 104 | | |||
105 | void MediaButton::slotAboutToShow() | 105 | void MediaButton::slotAboutToShow() | ||
106 | { | 106 | { | ||
107 | emit aboutToShow(); | 107 | emit aboutToShow(); | ||
108 | 108 | | |||
109 | popupMenu->clear(); | 109 | popupMenu->clear(); | ||
110 | udiNameMap.clear(); | 110 | udiNameMap.clear(); | ||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | 153 | if (krMtMan.networkFilesystem((*it2)->mountType()) && | |||
156 | break; | 156 | break; | ||
157 | } | 157 | } | ||
158 | } | 158 | } | ||
159 | 159 | | |||
160 | QString name = i18nc("%1 is the mount point of the remote share", "Remote Share [%1]", (*it)->mountPoint()); | 160 | QString name = i18nc("%1 is the mount point of the remote share", "Remote Share [%1]", (*it)->mountPoint()); | ||
161 | QStringList overlays; | 161 | QStringList overlays; | ||
162 | if (mounted) | 162 | if (mounted) | ||
163 | overlays << "emblem-mounted"; | 163 | overlays << "emblem-mounted"; | ||
164 | QAction * act = popupMenu->addAction(KDE::icon("network-wired", overlays), name); | 164 | QAction * act = popupMenu->addAction(Icon("network-wired", overlays), name); | ||
165 | QString udi = remotePrefix + (*it)->mountPoint(); | 165 | QString udi = remotePrefix + (*it)->mountPoint(); | ||
166 | act->setData(QVariant(udi)); | 166 | act->setData(QVariant(udi)); | ||
167 | } | 167 | } | ||
168 | } | 168 | } | ||
169 | 169 | | |||
170 | mountCheckerTimer.setSingleShot(true); | 170 | mountCheckerTimer.setSingleShot(true); | ||
171 | mountCheckerTimer.start(1000); | 171 | mountCheckerTimer.start(1000); | ||
172 | } | 172 | } | ||
173 | 173 | | |||
174 | bool MediaButton::getNameAndIcon(Solid::Device & device, QString &name, QIcon &iconOut) | 174 | bool MediaButton::getNameAndIcon(Solid::Device & device, QString &name, QIcon &iconOut) | ||
175 | { | 175 | { | ||
176 | Solid::StorageAccess *access = device.as<Solid::StorageAccess>(); | 176 | Solid::StorageAccess *access = device.as<Solid::StorageAccess>(); | ||
177 | if (access == 0) | 177 | if (access == 0) | ||
178 | return false; | 178 | return false; | ||
179 | 179 | | |||
180 | QString udi = device.udi(); | 180 | QString udi = device.udi(); | ||
181 | QString label = i18nc("Unknown label", "Unknown"); | 181 | QString label = i18nc("Unknown label", "Unknown"); | ||
182 | bool mounted = access->isAccessible(); | 182 | bool mounted = access->isAccessible(); | ||
183 | QString path = access->filePath(); | 183 | QString path = access->filePath(); | ||
184 | QString type = i18nc("Unknown media type", "Unknown"); | 184 | QString type = i18nc("Unknown media type", "Unknown"); | ||
185 | QString icon = device.icon(); | 185 | QString iconName = device.icon(); | ||
186 | QString fstype; | 186 | QString fstype; | ||
187 | QString size; | 187 | QString size; | ||
188 | 188 | | |||
189 | Solid::StorageVolume * vol = device.as<Solid::StorageVolume> (); | 189 | Solid::StorageVolume * vol = device.as<Solid::StorageVolume> (); | ||
190 | if (vol) { | 190 | if (vol) { | ||
191 | label = vol->label(); | 191 | label = vol->label(); | ||
192 | fstype = vol->fsType(); | 192 | fstype = vol->fsType(); | ||
193 | size = KIO::convertSize(vol->size()); | 193 | size = KIO::convertSize(vol->size()); | ||
194 | } | 194 | } | ||
195 | 195 | | |||
196 | bool printSize = false; | 196 | bool printSize = false; | ||
197 | 197 | | |||
198 | if (icon == "media-floppy") | 198 | if (iconName == "media-floppy") | ||
199 | type = i18n("Floppy"); | 199 | type = i18n("Floppy"); | ||
200 | else if (icon == "drive-optical") | 200 | else if (iconName == "drive-optical") | ||
201 | type = i18n("CD/DVD-ROM"); | 201 | type = i18n("CD/DVD-ROM"); | ||
202 | else if (icon == "drive-removable-media-usb-pendrive") | 202 | else if (iconName == "drive-removable-media-usb-pendrive") | ||
203 | type = i18n("USB pen drive"), printSize = true; | 203 | type = i18n("USB pen drive"), printSize = true; | ||
204 | else if (icon == "drive-removable-media-usb") | 204 | else if (iconName == "drive-removable-media-usb") | ||
205 | type = i18n("USB device"), printSize = true; | 205 | type = i18n("USB device"), printSize = true; | ||
206 | else if (icon == "drive-removable-media") | 206 | else if (iconName == "drive-removable-media") | ||
207 | type = i18n("Removable media"), printSize = true; | 207 | type = i18n("Removable media"), printSize = true; | ||
208 | else if (icon == "drive-harddisk") | 208 | else if (iconName == "drive-harddisk") | ||
209 | type = i18n("Hard Disk"), printSize = true; | 209 | type = i18n("Hard Disk"), printSize = true; | ||
210 | else if (icon == "camera-photo") | 210 | else if (iconName == "camera-photo") | ||
211 | type = i18n("Camera"); | 211 | type = i18n("Camera"); | ||
212 | else if (icon == "media-optical-video") | 212 | else if (iconName == "media-optical-video") | ||
213 | type = i18n("Video CD/DVD-ROM"); | 213 | type = i18n("Video CD/DVD-ROM"); | ||
214 | else if (icon == "media-optical-audio") | 214 | else if (iconName == "media-optical-audio") | ||
215 | type = i18n("Audio CD/DVD-ROM"); | 215 | type = i18n("Audio CD/DVD-ROM"); | ||
216 | else if (icon == "media-optical") | 216 | else if (iconName == "media-optical") | ||
217 | type = i18n("Recordable CD/DVD-ROM"); | 217 | type = i18n("Recordable CD/DVD-ROM"); | ||
218 | 218 | | |||
219 | KConfigGroup cfg(KSharedConfig::openConfig(), QStringLiteral("MediaMenu")); | 219 | KConfigGroup cfg(KSharedConfig::openConfig(), QStringLiteral("MediaMenu")); | ||
220 | 220 | | |||
221 | if (printSize) { | 221 | if (printSize) { | ||
222 | QString showSizeSetting = cfg.readEntry("ShowSize", "Always"); | 222 | QString showSizeSetting = cfg.readEntry("ShowSize", "Always"); | ||
223 | if (showSizeSetting == "WhenNoLabel") | 223 | if (showSizeSetting == "WhenNoLabel") | ||
224 | printSize = label.isEmpty(); | 224 | printSize = label.isEmpty(); | ||
Show All 18 Lines | |||||
243 | if (mounted) { | 243 | if (mounted) { | ||
244 | overlays << "emblem-mounted"; | 244 | overlays << "emblem-mounted"; | ||
245 | } else { | 245 | } else { | ||
246 | overlays << QString(); // We have to guarantee the placement of the next emblem | 246 | overlays << QString(); // We have to guarantee the placement of the next emblem | ||
247 | } | 247 | } | ||
248 | if (vol && vol->usage() == Solid::StorageVolume::Encrypted) { | 248 | if (vol && vol->usage() == Solid::StorageVolume::Encrypted) { | ||
249 | overlays << "security-high"; | 249 | overlays << "security-high"; | ||
250 | } | 250 | } | ||
251 | iconOut = KDE::icon(icon, overlays); | 251 | iconOut = Icon(iconName, overlays); | ||
252 | return true; | 252 | return true; | ||
253 | } | 253 | } | ||
254 | 254 | | |||
255 | void MediaButton::slotPopupActivated(QAction *action) | 255 | void MediaButton::slotPopupActivated(QAction *action) | ||
256 | { | 256 | { | ||
257 | if (action && action->data().canConvert<QString>()) { | 257 | if (action && action->data().canConvert<QString>()) { | ||
258 | QString udi = action->data().toString(); | 258 | QString udi = action->data().toString(); | ||
259 | if (!udi.isEmpty()) { | 259 | if (!udi.isEmpty()) { | ||
▲ Show 20 Lines • Show All 350 Lines • ▼ Show 20 Line(s) | 607 | if (krMtMan.networkFilesystem((*it2)->mountType()) && | |||
610 | break; | 610 | break; | ||
611 | } | 611 | } | ||
612 | } | 612 | } | ||
613 | 613 | | |||
614 | QString name = i18nc("%1 is the mount point of the remote share", "Remote Share [%1]", (*it)->mountPoint()); | 614 | QString name = i18nc("%1 is the mount point of the remote share", "Remote Share [%1]", (*it)->mountPoint()); | ||
615 | QStringList overlays; | 615 | QStringList overlays; | ||
616 | if (mounted) | 616 | if (mounted) | ||
617 | overlays << "emblem-mounted"; | 617 | overlays << "emblem-mounted"; | ||
618 | QIcon kdeIcon = KDE::icon("network-wired", overlays); | 618 | QIcon kdeIcon = Icon("network-wired", overlays); | ||
619 | 619 | | |||
620 | if (!correspondingAct) { | 620 | if (!correspondingAct) { | ||
621 | QAction * act = popupMenu->addAction(kdeIcon, name); | 621 | QAction * act = popupMenu->addAction(kdeIcon, name); | ||
622 | act->setData(QVariant(udi)); | 622 | act->setData(QVariant(udi)); | ||
623 | } else { | 623 | } else { | ||
624 | correspondingAct->setText(name); | 624 | correspondingAct->setText(name); | ||
625 | correspondingAct->setIcon(kdeIcon); | 625 | correspondingAct->setIcon(kdeIcon); | ||
626 | } | 626 | } | ||
627 | } | 627 | } | ||
628 | } | 628 | } | ||
629 | 629 | | |||
630 | mountCheckerTimer.setSingleShot(true); | 630 | mountCheckerTimer.setSingleShot(true); | ||
631 | mountCheckerTimer.start(1000); | 631 | mountCheckerTimer.start(1000); | ||
632 | } | 632 | } | ||
633 | 633 | |