sms: Added opening kdeconnect-sms on the plasmoid and indicator

Add a menu entry on the kdeconnect-indicator within devices' submenu that opens kdeconnect-sms.
Also add it in the plasmoid in the device delegate.
This commit is contained in:
Aleix Pol 2019-07-20 16:02:38 +02:00
parent bc468f1e07
commit b7f8ceefcf
8 changed files with 50 additions and 11 deletions

View file

@ -113,10 +113,18 @@ DeviceIndicator::DeviceIndicator(DeviceDbusInterface* device)
setWhenAvailable(device->hasPlugin(QStringLiteral("kdeconnect_share")), [sendFile](bool available) { sendFile->setVisible(available); }, this);
if (!QStandardPaths::findExecutable(QStringLiteral("kdeconnect-sms")).isEmpty()) {
auto smsapp = addAction(QIcon::fromTheme(QStringLiteral("message-new")), i18n("SMS Messages..."));
QObject::connect(smsapp, &QAction::triggered, device, [device] () {
QProcess::startDetached(QLatin1String("kdeconnect-sms"), { QStringLiteral("--device"), device->id() });
});
setWhenAvailable(device->hasPlugin(QStringLiteral("kdeconnect_sms")), [smsapp](bool available) { smsapp->setVisible(available); }, this);
}
QMenu* remoteCommandsMenu = new QMenu(i18n("Run command"), this);
QAction* menuAction = remoteCommandsMenu->menuAction();
QAction* addCommandAction = remoteCommandsMenu->addAction(QIcon::fromTheme(QStringLiteral("list-add")), i18n("Add commands"));
connect(addCommandAction, &QAction::triggered, m_remoteCommandsInterface, &RemoteCommandsDbusInterface::editCommands);
addAction(menuAction);

View file

@ -68,7 +68,7 @@ int main(int argc, char** argv)
// Get bundle path
CFURLRef url = (CFURLRef)CFAutorelease((CFURLRef)CFBundleCopyBundleURL(CFBundleGetMainBundle()));
QString basePath = QUrl::fromCFURL(url).path();
// Start kdeconnectd
QProcess kdeconnectdProcess;
kdeconnectdProcess.startDetached(basePath + QStringLiteral("Contents/MacOS/kdeconnectd"));

View file

@ -71,7 +71,7 @@ public:
Q_SCRIPTABLE DeviceDbusInterface* getDevice(int row) const;
QHash<int, QByteArray> roleNames() const override;
int rowForDevice(const QString& id) const;
Q_SCRIPTABLE int rowForDevice(const QString& id) const;
private Q_SLOTS:
void deviceAdded(const QString& id);

View file

@ -142,6 +142,23 @@ PlasmaComponents.ListItem
}
}
//SMS
PlasmaComponents.Button
{
SMS {
id: sms
device: root.device
}
iconSource: "message-new'"
visible: sms.available
tooltip: i18n("SMS Messages")
onClicked: {
sms.plugin.launchApp()
}
}
height: browse.height
width: parent.width
}

View file

@ -27,6 +27,7 @@
#include <QDebug>
#include <QDBusConnection>
#include <QLoggingCategory>
#include <QProcess>
#include <core/device.h>
#include <core/daemon.h>
@ -116,11 +117,15 @@ bool SmsPlugin::handleBatchMessages(const NetworkPacket& np)
return true;
}
QString SmsPlugin::dbusPath() const
{
return QStringLiteral("/modules/kdeconnect/devices/") + device()->id() + QStringLiteral("/sms");
}
void SmsPlugin::launchApp()
{
QProcess::startDetached(QLatin1String("kdeconnect-sms"), { QStringLiteral("--device"), device()->id() });
}
#include "smsplugin.moc"

View file

@ -140,6 +140,8 @@ public Q_SLOTS:
*/
Q_SCRIPTABLE void requestConversation(const qint64& conversationID) const;
Q_SCRIPTABLE void launchApp();
private:
/**

View file

@ -41,20 +41,20 @@ int main(int argc, char *argv[])
aboutData.addAuthor(i18n("Nicolas Fella"), {}, QStringLiteral("nicolas.fella@gmx.de"));
KAboutData::setApplicationData(aboutData);
QString initialMessage;
QString initialMessage, deviceid;
{
QCommandLineParser parser;
aboutData.setupCommandLine(&parser);
parser.addVersionOption();
parser.addHelpOption();
parser.addOption(QCommandLineOption(QStringLiteral("device"), i18n("Select a device"), i18n("id")));
parser.addOption(QCommandLineOption(QStringLiteral("message"), i18n("Send a message"), i18n("message")));
parser.process(app);
aboutData.processCommandLine(&parser);
if (parser.isSet(QStringLiteral("message"))) {
initialMessage = parser.value(QStringLiteral("message"));
}
initialMessage = parser.value(QStringLiteral("message"));
deviceid = parser.value(QStringLiteral("device"));
}
KDBusService service(KDBusService::Unique);
@ -66,8 +66,11 @@ int main(int argc, char *argv[])
QQmlApplicationEngine engine;
engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
engine.rootContext()->setContextProperty(QStringLiteral("_initialMessage"), QVariant(initialMessage));
engine.rootContext()->setContextProperty(QStringLiteral("aboutData"), QVariant::fromValue(KAboutData::applicationData()));
engine.rootContext()->setContextProperties({
{ QStringLiteral("initialMessage"), initialMessage },
{ QStringLiteral("initialDevice"), deviceid },
{ QStringLiteral("aboutData"), QVariant::fromValue(KAboutData::applicationData()) }
});
engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
return app.exec();

View file

@ -73,6 +73,7 @@ Kirigami.ScrollablePage
}
property string initialMessage
property string initialDevice
header: Kirigami.InlineMessage {
Layout.fillWidth: true
@ -97,7 +98,10 @@ Kirigami.ScrollablePage
//TODO: make it possible to filter if they can do sms
sourceModel: DevicesModel { displayFilter: DevicesModel.Paired | DevicesModel.Reachable }
onRowsInserted: if (devicesCombo.currentIndex < 0) {
devicesCombo.currentIndex = 0
if (page.initialDevice)
devicesCombo.currentIndex = devicesModel.rowForDevice(page.initialDevice);
else
devicesCombo.currentIndex = 0
}
}
textRole: "display"