diff --git a/ChangeLog b/ChangeLog index 9591a22..53355c9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ qcma (0.3.0) unstable; urgency=low * Headless qcma version. + * Added dbus controls to qcma (Linux only) * Set the default video codec to h264 if metadata skip is enabled. * Delay the progress dialog by one second so it doesn't show on quick scans. * Do not show the disconnect message if no connection is established. diff --git a/qcma_cli.pro b/qcma_cli.pro index bd138b1..3d35592 100644 --- a/qcma_cli.pro +++ b/qcma_cli.pro @@ -25,4 +25,3 @@ system(qdbuscpp2xml -M -s src/cli/headlessmanager.h -o org.qcma.HeadlessManager. # Create the helper class DBUS_ADAPTORS = org.qcma.HeadlessManager.xml - diff --git a/qcma_gui.pro b/qcma_gui.pro index 984d645..a7bb793 100644 --- a/qcma_gui.pro +++ b/qcma_gui.pro @@ -65,3 +65,14 @@ unix:!macx { HEADERS += src/kdenotifier.h } } + +unix:!macx { + +QT += dbus + +# Create the introspection XML +system(qdbuscpp2xml -M -s src/gui/mainwidget.h -o org.qcma.ClientManager.xml) + +# Create the helper class +DBUS_ADAPTORS = org.qcma.ClientManager.xml +} diff --git a/src/gui/clientmanager.cpp b/src/gui/clientmanager.cpp index 7cce9d9..af0960e 100644 --- a/src/gui/clientmanager.cpp +++ b/src/gui/clientmanager.cpp @@ -45,6 +45,7 @@ void ClientManager::databaseUpdated(int count) } else { emit messageSent(tr("Database indexing aborted by user")); } + emit updated(count); } void ClientManager::showPinDialog(QString name, int pin) diff --git a/src/gui/clientmanager.h b/src/gui/clientmanager.h index 57b41df..a6af841 100644 --- a/src/gui/clientmanager.h +++ b/src/gui/clientmanager.h @@ -50,15 +50,18 @@ private: QThread *wireless_thread; signals: + void updated(int); void stopped(); void receivedPin(int); void deviceDisconnected(); void messageSent(QString); void deviceConnected(QString); +public slots: + void refreshDatabase(); + private slots: void threadStopped(); - void refreshDatabase(); void databaseUpdated(int count); void showPinDialog(QString name, int pin); }; diff --git a/src/gui/main.cpp b/src/gui/main.cpp index 1ebebe5..ac77830 100644 --- a/src/gui/main.cpp +++ b/src/gui/main.cpp @@ -110,8 +110,10 @@ int main(int argc, char *argv[]) //TODO: check if this is actually needed since we don't have a main window by default QApplication::setQuitOnLastWindowClosed(false); + bool showSystray = app.arguments().contains("--no-systray"); + MainWidget widget; - widget.prepareApplication(); + widget.prepareApplication(showSystray); // receive the message from another process QObject::connect(&app, SIGNAL(messageAvailable(QString)), &widget, SLOT(receiveMessage(QString))); diff --git a/src/gui/mainwidget.cpp b/src/gui/mainwidget.cpp index e6c178e..55e19f6 100644 --- a/src/gui/mainwidget.cpp +++ b/src/gui/mainwidget.cpp @@ -21,6 +21,10 @@ #include "cmaclient.h" #include "cmautils.h" +#ifdef Q_OS_LINUX +#include "clientmanager_adaptor.h" +#endif + #include "qlistdb.h" #include "sqlitedb.h" @@ -44,10 +48,32 @@ const QStringList MainWidget::path_list = QStringList() << "photoPath" << "music bool sleptOnce = false; +#ifdef Q_OS_LINUX +MainWidget::MainWidget(QWidget *parent) : + QWidget(parent), db(NULL), configForm(NULL), managerForm(NULL), backupForm(NULL), dbus_conn(QDBusConnection::sessionBus()) +{ + new ClientManagerAdaptor(this); + QDBusConnection dbus = QDBusConnection::sessionBus(); + // expose qcma over dbus so the database update can be triggered + dbus.registerObject("/ClientManager", this); + dbus.registerService("org.qcma.ClientManager"); +#ifndef ENABLE_KDE_NOTIFIER + trayIcon = NULL; +#else + notifierItem = NULL; +#endif +} +#else MainWidget::MainWidget(QWidget *parent) : QWidget(parent), db(NULL), configForm(NULL), managerForm(NULL), backupForm(NULL) { +#ifndef ENABLE_KDE_NOTIFIER + trayIcon = NULL; +#else + notifierItem = NULL; +#endif } +#endif void MainWidget::checkSettings() { @@ -101,7 +127,7 @@ void MainWidget::deviceDisconnect() receiveMessage(tr("The device has been disconnected")); } -void MainWidget::deviceConnected(QString message) +void MainWidget::deviceConnect(QString message) { #ifndef ENABLE_KDE_NOTIFIER #ifndef Q_OS_WIN32 @@ -117,7 +143,7 @@ void MainWidget::deviceConnected(QString message) receiveMessage(message); } -void MainWidget::prepareApplication() +void MainWidget::prepareApplication(bool showSystray) { //TODO: delete database before exit if(QSettings().value("useMemoryStorage", true).toBool()) { @@ -130,7 +156,11 @@ void MainWidget::prepareApplication() backupForm = new BackupManagerForm(db, this); managerForm = new ClientManager(db, this); connectSignals(); - createTrayIcon(); + + if(showSystray) { + createTrayIcon(); + } + checkSettings(); } @@ -138,19 +168,22 @@ void MainWidget::connectSignals() { connect(configForm, SIGNAL(finished(int)), this, SLOT(dialogResult(int))); connect(managerForm, SIGNAL(stopped()), qApp, SLOT(quit())); - connect(managerForm, SIGNAL(deviceConnected(QString)), this, SLOT(deviceConnected(QString))); - connect(managerForm, SIGNAL(deviceDisconnected()), this, SLOT(deviceDisconnect())); - connect(managerForm, SIGNAL(messageSent(QString)), this, SLOT(receiveMessage(QString))); - - //backupForm.db = managerForm.db; + connect(managerForm, SIGNAL(deviceConnected(QString)), this, SIGNAL(deviceConnected(QString))); + connect(managerForm, SIGNAL(deviceDisconnected()), this, SIGNAL(deviceDisconnected())); + connect(managerForm, SIGNAL(messageSent(QString)), this, SIGNAL(messageReceived(QString))); + connect(managerForm, SIGNAL(updated(int)), this, SIGNAL(databaseUpdated(int))); } void MainWidget::setTrayTooltip(QString message) { #ifndef ENABLE_KDE_NOTIFIER - trayIcon->setToolTip(message); + if(trayIcon) { + trayIcon->setToolTip(message); + } #else - notifierItem->setToolTipSubTitle(message); + if(notifierItem) { + notifierItem->setToolTipSubTitle(message); + } #endif } @@ -189,6 +222,16 @@ void MainWidget::showAboutQt() QMessageBox::aboutQt(this); } +void MainWidget::openConfig() +{ + configForm->open(); +} + +void MainWidget::refreshDatabase() +{ + managerForm->refreshDatabase(); +} + void MainWidget::createTrayIcon() { options = new QAction(tr("&Settings"), this); @@ -198,9 +241,9 @@ void MainWidget::createTrayIcon() about_qt = new QAction(tr("Abou&t Qt"), this); quit = new QAction(tr("&Quit"), this); - connect(options, SIGNAL(triggered()), configForm, SLOT(open())); + connect(options, SIGNAL(triggered()), this, SLOT(openConfig())); connect(backup, SIGNAL(triggered()), this, SLOT(openManager())); - connect(reload, SIGNAL(triggered()), managerForm, SLOT(refreshDatabase())); + connect(reload, SIGNAL(triggered()), this, SLOT(refreshDatabase())); connect(about, SIGNAL(triggered()), this, SLOT(showAboutDialog())); connect(about_qt, SIGNAL(triggered()), this, SLOT(showAboutQt())); connect(quit, SIGNAL(triggered()), this, SLOT(stopServer())); @@ -241,6 +284,10 @@ void MainWidget::createTrayIcon() notifierItem->setToolTipSubTitle(tr("Disconnected")); notifierItem->setStandardActionsEnabled(false); #endif + + connect(managerForm, SIGNAL(deviceConnected(QString)), this, SLOT(deviceConnect(QString))); + connect(managerForm, SIGNAL(deviceDisconnected()), this, SLOT(deviceDisconnect())); + connect(managerForm, SIGNAL(messageSent(QString)), this, SLOT(receiveMessage(QString))); } void MainWidget::receiveMessage(QString message) @@ -265,7 +312,9 @@ void MainWidget::receiveMessage(QString message) MainWidget::~MainWidget() { #ifndef ENABLE_KDE_NOTIFIER - trayIcon->hide(); + if(trayIcon) { + trayIcon->hide(); + } #endif delete db; } diff --git a/src/gui/mainwidget.h b/src/gui/mainwidget.h index ac80db3..a0be5b9 100644 --- a/src/gui/mainwidget.h +++ b/src/gui/mainwidget.h @@ -34,16 +34,22 @@ #include "kdenotifier.h" #endif +#ifdef Q_OS_LINUX +#include +#endif + #include class MainWidget : public QWidget { Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.qcma.ClientManager") + public: explicit MainWidget(QWidget *parent = 0); ~MainWidget(); - void prepareApplication(); + void prepareApplication(bool showSystray); private: void connectSignals(); @@ -68,6 +74,10 @@ private: QAction *about; QAction *about_qt; +#ifdef Q_OS_LINUX + QDBusConnection dbus_conn; +#endif + #ifndef ENABLE_KDE_NOTIFIER QSystemTrayIcon *trayIcon; #else @@ -76,12 +86,22 @@ private: const static QStringList path_list; -private slots: - void stopServer(); +signals: + Q_SCRIPTABLE void deviceConnected(QString); + Q_SCRIPTABLE void deviceDisconnected(); + Q_SCRIPTABLE void databaseUpdated(int count); + Q_SCRIPTABLE void messageReceived(QString message); + +public slots: + void openConfig(); void openManager(); void showAboutQt(); void showAboutDialog(); - void deviceConnected(QString message); + void refreshDatabase(); + void stopServer(); + +private slots: + void deviceConnect(QString message); void deviceDisconnect(); void dialogResult(int result); void receiveMessage(QString message); diff --git a/src/sqlitedb.cpp b/src/sqlitedb.cpp index 6557717..2ae99c0 100644 --- a/src/sqlitedb.cpp +++ b/src/sqlitedb.cpp @@ -386,7 +386,7 @@ int SQLiteDB::insertObjectEntry(const QString &path, const QString &name, int pa int SQLiteDB::insertObjectEntryInternal(const QString &path, const QString &name, int parent_ohfi, int root_ohfi) { - int ohfi; + int ohfi = 0; QFileInfo info(path, name); if(info.isDir()) {