Port kdeconnect-cli away from kdelibs4supposrt
This commit is contained in:
parent
be885903e6
commit
1abf0686f5
2 changed files with 36 additions and 33 deletions
|
@ -2,6 +2,6 @@ include_directories(${CMAKE_SOURCE_DIR})
|
|||
|
||||
add_executable(kdeconnect-cli kdeconnect-cli.cpp)
|
||||
|
||||
target_link_libraries(kdeconnect-cli kdeconnectinterfaces Qt5::Gui KF5::KDELibs4Support)
|
||||
target_link_libraries(kdeconnect-cli kdeconnectinterfaces Qt5::Gui KF5::CoreAddons KF5::I18n)
|
||||
|
||||
install(TARGETS kdeconnect-cli ${INSTALL_TARGETS_DEFAULT_ARGS})
|
||||
|
|
|
@ -18,36 +18,39 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <KApplication>
|
||||
#include <kcmdlineargs.h>
|
||||
#include <k4aboutdata.h>
|
||||
#include <interfaces/devicesmodel.h>
|
||||
#include <interfaces/notificationsmodel.h>
|
||||
#include <interfaces/dbusinterfaces.h>
|
||||
#include <iostream>
|
||||
#include <QDBusMessage>
|
||||
#include <QDBusConnection>
|
||||
#include <QGuiApplication>
|
||||
#include <KAboutData>
|
||||
#include <KLocalizedString>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
K4AboutData about("kdeconnect-cli", "kdeconnect-cli", ki18n(("kdeconnect-cli")), "1.0", ki18n("KDE Connect CLI tool"),
|
||||
K4AboutData::License_GPL, ki18n("(C) 2013 Aleix Pol Gonzalez"));
|
||||
QGuiApplication app(argc, argv);
|
||||
KAboutData about("kdeconnect-cli", i18n("kdeconnect-cli"), "1.0", i18n("KDE Connect CLI tool"),
|
||||
KAboutLicense::GPL, i18n("(C) 2013 Aleix Pol Gonzalez"));
|
||||
KAboutData::setApplicationData(about);
|
||||
|
||||
about.addAuthor( ki18n("Aleix Pol Gonzalez"), KLocalizedString(), "aleixpol@kde.org" );
|
||||
KCmdLineArgs::init(argc, argv, &about);
|
||||
KCmdLineOptions options;
|
||||
options.add("l")
|
||||
.add("list-devices", ki18n("List all devices"));
|
||||
options.add("share <path>", ki18n("Share a file to a said device"));
|
||||
options.add("pair", ki18n("Request pairing to a said device"));
|
||||
options.add("unpair", ki18n("Stop pairing to a said device"));
|
||||
options.add("ping", ki18n("Sends a ping to said device"));
|
||||
options.add("list-notifications", ki18n("Display the notifications on a said device"));
|
||||
options.add("device <dev>", ki18n("Device ID"));
|
||||
KCmdLineArgs::addCmdLineOptions( options );
|
||||
KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
|
||||
KApplication app;
|
||||
if(args->isSet("l")) {
|
||||
about.addAuthor( i18n("Aleix Pol Gonzalez"), QString(), "aleixpol@kde.org" );
|
||||
QCommandLineParser parser;
|
||||
parser.addOption(QCommandLineOption(QStringList("l") << "list-devices", i18n("List all devices")));
|
||||
parser.addOption(QCommandLineOption("share", i18n("Share a file to a said device"), "path"));
|
||||
parser.addOption(QCommandLineOption("pair", i18n("Request pairing to a said device")));
|
||||
parser.addOption(QCommandLineOption("unpair", i18n("Stop pairing to a said device")));
|
||||
parser.addOption(QCommandLineOption("ping", i18n("Sends a ping to said device")));
|
||||
parser.addOption(QCommandLineOption("list-notifications", i18n("Display the notifications on a said device")));
|
||||
parser.addOption(QCommandLineOption("device", i18n("Device ID"), "dev"));
|
||||
about.setupCommandLine(&parser);
|
||||
|
||||
parser.addHelpOption();
|
||||
parser.process(app);
|
||||
about.processCommandLine(&parser);
|
||||
|
||||
if(parser.isSet("l")) {
|
||||
DevicesModel devices;
|
||||
for(int i=0, rows=devices.rowCount(); i<rows; ++i) {
|
||||
QModelIndex idx = devices.index(i);
|
||||
|
@ -69,21 +72,21 @@ int main(int argc, char** argv)
|
|||
std::cout << devices.rowCount() << " devices found" << std::endl;
|
||||
} else {
|
||||
QString device;
|
||||
if(!args->isSet("device")) {
|
||||
KCmdLineArgs::usageError(i18n("No device specified"));
|
||||
if(!parser.isSet("device")) {
|
||||
qCritical() << (i18n("No device specified"));
|
||||
}
|
||||
device = args->getOption("device");
|
||||
device = parser.value("device");
|
||||
QUrl url;
|
||||
if(args->isSet("share")) {
|
||||
url = args->makeURL(args->getOption("share").toLatin1());
|
||||
args->clear();
|
||||
if(parser.isSet("share")) {
|
||||
url = QUrl::fromUserInput(parser.value("share"));
|
||||
parser.clearPositionalArguments();
|
||||
if(!url.isEmpty() && !device.isEmpty()) {
|
||||
QDBusMessage msg = QDBusMessage::createMethodCall("org.kde.kdeconnect", "/modules/kdeconnect/devices/"+device+"/share", "org.kde.kdeconnect.device.share", "shareUrl");
|
||||
msg.setArguments(QVariantList() << url.toString());
|
||||
QDBusConnection::sessionBus().call(msg);
|
||||
} else
|
||||
KCmdLineArgs::usageError(i18n("Couldn't share %1", url.toString()));
|
||||
} else if(args->isSet("pair")) {
|
||||
qCritical() << (i18n("Couldn't share %1", url.toString()));
|
||||
} else if(parser.isSet("pair")) {
|
||||
DeviceDbusInterface dev(device);
|
||||
if(dev.isPaired())
|
||||
std::cout << "Already paired" << std::endl;
|
||||
|
@ -91,7 +94,7 @@ int main(int argc, char** argv)
|
|||
QDBusPendingReply<void> req = dev.requestPair();
|
||||
req.waitForFinished();
|
||||
}
|
||||
} else if(args->isSet("unpair")) {
|
||||
} else if(parser.isSet("unpair")) {
|
||||
DeviceDbusInterface dev(device);
|
||||
if(!dev.isPaired())
|
||||
std::cout << "Already not paired" << std::endl;
|
||||
|
@ -99,10 +102,10 @@ int main(int argc, char** argv)
|
|||
QDBusPendingReply<void> req = dev.unpair();
|
||||
req.waitForFinished();
|
||||
}
|
||||
} else if(args->isSet("ping")) {
|
||||
} else if(parser.isSet("ping")) {
|
||||
QDBusMessage msg = QDBusMessage::createMethodCall("org.kde.kdeconnect", "/modules/kdeconnect/devices/"+device+"/ping", "org.kde.kdeconnect.device.ping", "sendPing");
|
||||
QDBusConnection::sessionBus().call(msg);
|
||||
} else if(args->isSet("list-notifications")) {
|
||||
} else if(parser.isSet("list-notifications")) {
|
||||
NotificationsModel notifications;
|
||||
notifications.setDeviceId(device);
|
||||
for(int i=0, rows=notifications.rowCount(); i<rows; ++i) {
|
||||
|
@ -111,7 +114,7 @@ int main(int argc, char** argv)
|
|||
<< ": " << idx.data(NotificationsModel::NameModelRole).toString().toStdString() << std::endl;
|
||||
}
|
||||
} else {
|
||||
KCmdLineArgs::usageError(i18n("Nothing to be done with the device"));
|
||||
qCritical() << i18n("Nothing to be done with the device");
|
||||
}
|
||||
}
|
||||
QMetaObject::invokeMethod(&app, "quit", Qt::QueuedConnection);
|
||||
|
|
Loading…
Reference in a new issue