diff --git a/indicator/deviceindicator.cpp b/indicator/deviceindicator.cpp index 856bc6b1..dc77d3c4 100644 --- a/indicator/deviceindicator.cpp +++ b/indicator/deviceindicator.cpp @@ -1,109 +1,111 @@ /* * Copyright 2016 Aleix Pol Gonzalez * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "deviceindicator.h" #include #include class BatteryAction : public QAction { Q_OBJECT public: BatteryAction(DeviceDbusInterface* device) : QAction(nullptr) , m_batteryIface(new DeviceBatteryDbusInterface(device->id(), this)) { setWhenAvailable(m_batteryIface->charge(), [this](int charge) { setCharge(charge); }, this); setWhenAvailable(m_batteryIface->isCharging(), [this](bool charging) { setCharging(charging); }, this); connect(m_batteryIface, SIGNAL(chargeChanged(int)), this, SLOT(setCharge(int))); connect(m_batteryIface, SIGNAL(stateChanged(bool)), this, SLOT(setCharging(bool))); + setIcon(QIcon::fromTheme(QStringLiteral("battery"))); + update(); } void update() { if (m_charge < 0) setText(i18n("No Battery")); else if (m_charging) setText(i18n("Battery: %1% (Charging)", m_charge)); else setText(i18n("Battery: %1%", m_charge)); } private Q_SLOTS: void setCharge(int charge) { m_charge = charge; update(); } void setCharging(bool charging) { m_charging = charging; update(); } private: DeviceBatteryDbusInterface* m_batteryIface; int m_charge = -1; bool m_charging = false; }; DeviceIndicator::DeviceIndicator(DeviceDbusInterface* device) : QMenu(device->name(), nullptr) , m_device(device) { #ifdef Q_OS_WIN setIcon(QIcon(QStandardPaths::locate(QStandardPaths::AppDataLocation, "icons/hicolor/scalable/status/"+device->iconName()+".svg"))); #else setIcon(QIcon::fromTheme(device->iconName())); #endif connect(device, SIGNAL(nameChanged(QString)), this, SLOT(setText(QString))); auto battery = new BatteryAction(device); addAction(battery); setWhenAvailable(device->hasPlugin("kdeconnect_battery"), [battery](bool available) { battery->setVisible(available); } , this); - auto browse = addAction(i18n("Browse device")); + auto browse = addAction(QIcon::fromTheme(QStringLiteral("document-open-folder")), i18n("Browse device")); connect(browse, &QAction::triggered, device, [device](){ SftpDbusInterface* sftpIface = new SftpDbusInterface(device->id(), device); sftpIface->startBrowsing(); sftpIface->deleteLater(); }); setWhenAvailable(device->hasPlugin("kdeconnect_sftp"), [browse](bool available) { browse->setVisible(available); }, this); - auto findDevice = addAction(i18n("Ring device")); + auto findDevice = addAction(QIcon::fromTheme(QStringLiteral("irc-voice")), i18n("Ring device")); connect(findDevice, &QAction::triggered, device, [device](){ FindMyPhoneDeviceDbusInterface* iface = new FindMyPhoneDeviceDbusInterface(device->id(), device); iface->ring(); iface->deleteLater(); }); setWhenAvailable(device->hasPlugin("kdeconnect_findmyphone"), [findDevice](bool available) { findDevice->setVisible(available); }, this); - auto sendFile = addAction(i18n("Send file")); + auto sendFile = addAction(QIcon::fromTheme(QStringLiteral("document-share")), i18n("Send file")); connect(sendFile, &QAction::triggered, device, [device, this](){ const QUrl url = QFileDialog::getOpenFileUrl(parentWidget(), i18n("Select file to send to '%1'", device->name()), QUrl::fromLocalFile(QDir::homePath())); if (url.isEmpty()) return; QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kdeconnect"), "/modules/kdeconnect/devices/"+device->id()+"/share", QStringLiteral("org.kde.kdeconnect.device.share"), QStringLiteral("shareUrl")); msg.setArguments(QVariantList() << url.toString()); QDBusConnection::sessionBus().call(msg); }); setWhenAvailable(device->hasPlugin("kdeconnect_share"), [sendFile](bool available) { sendFile->setVisible(available); }, this); } #include "deviceindicator.moc" diff --git a/indicator/main.cpp b/indicator/main.cpp index 415ac581..05f6c22a 100644 --- a/indicator/main.cpp +++ b/indicator/main.cpp @@ -1,132 +1,132 @@ /* * Copyright 2016 Aleix Pol Gonzalez * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include #include #include #ifdef QSYSTRAY #include #else #include #endif #include #include #include #include #include "interfaces/devicesmodel.h" #include "interfaces/notificationsmodel.h" #include "interfaces/dbusinterfaces.h" #include "kdeconnect-version.h" #include "deviceindicator.h" int main(int argc, char** argv) { QApplication app(argc, argv); KAboutData about("kdeconnect-indicator", i18n("KDE Connect Indicator"), QStringLiteral(KDECONNECT_VERSION_STRING), i18n("KDE Connect Indicator tool"), KAboutLicense::GPL, i18n("(C) 2016 Aleix Pol Gonzalez")); KAboutData::setApplicationData(about); #ifdef Q_OS_WIN QProcess::startDetached("kdeconnectd.exe"); #endif KDBusService dbusService(KDBusService::Unique); DevicesModel model; model.setDisplayFilter(DevicesModel::Reachable | DevicesModel::Paired); QMenu* menu = new QMenu; DaemonDbusInterface iface; auto refreshMenu = [&iface, &model, &menu]() { menu->clear(); - auto configure = menu->addAction(i18n("Configure...")); + auto configure = menu->addAction(QIcon::fromTheme(QStringLiteral("configure")), i18n("Configure...")); QObject::connect(configure, &QAction::triggered, configure, [](){ KCMultiDialog* dialog = new KCMultiDialog; dialog->addModule("kcm_kdeconnect"); dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->show(); }); for (int i=0, count = model.rowCount(); iaddMenu(indicator); } const QStringList requests = iface.pairingRequests(); if (!requests.isEmpty()) { menu->addSection(i18n("Pairing requests")); for(const auto& req: requests) { DeviceDbusInterface* dev = new DeviceDbusInterface(req, menu); auto pairMenu = menu->addMenu(dev->name()); pairMenu->addAction(i18n("Pair"), dev, &DeviceDbusInterface::acceptPairing); pairMenu->addAction(i18n("Reject"), dev, &DeviceDbusInterface::rejectPairing); } } }; QObject::connect(&iface, &DaemonDbusInterface::pairingRequestsChangedProxy, &model, refreshMenu); QObject::connect(&model, &DevicesModel::rowsInserted, &model, refreshMenu); QObject::connect(&model, &DevicesModel::rowsRemoved, &model, refreshMenu); #ifdef QSYSTRAY QSystemTrayIcon systray; systray.setIcon(QIcon::fromTheme("kdeconnect")); systray.setVisible(true); systray.setToolTip("KDE Connect"); QObject::connect(&model, &DevicesModel::rowsChanged, &model, [&systray, &model]() { systray.setToolTip(i18np("%1 device connected", "%1 devices connected", model.rowCount())); }); systray.setContextMenu(menu); #else KStatusNotifierItem systray; systray.setIconByName(QStringLiteral("kdeconnect")); systray.setToolTip(QStringLiteral("kdeconnect"), "KDE Connect", "KDE Connect"); systray.setCategory(KStatusNotifierItem::Communications); systray.setStatus(KStatusNotifierItem::Passive); systray.setStandardActionsEnabled(false); QObject::connect(&model, &DevicesModel::rowsChanged, &model, [&systray, &model]() { const auto count = model.rowCount(); systray.setStatus(count == 0 ? KStatusNotifierItem::Passive : KStatusNotifierItem::Active); systray.setToolTip(QStringLiteral("kdeconnect"), QStringLiteral("KDE Connect"), i18np("%1 device connected", "%1 devices connected", count)); }); systray.setContextMenu(menu); #endif refreshMenu(); app.setQuitOnLastWindowClosed(false); return app.exec(); }