Added dbus interface for regular qcma.

Added option to disable the systray: --no-systray.
This commit is contained in:
codestation
2014-04-19 23:05:20 -04:30
parent 24af4d428e
commit a4c2301cab
9 changed files with 107 additions and 21 deletions

View File

@@ -1,6 +1,7 @@
qcma (0.3.0) unstable; urgency=low qcma (0.3.0) unstable; urgency=low
* Headless qcma version. * Headless qcma version.
* Added dbus controls to qcma (Linux only)
* Set the default video codec to h264 if metadata skip is enabled. * 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. * 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. * Do not show the disconnect message if no connection is established.

View File

@@ -25,4 +25,3 @@ system(qdbuscpp2xml -M -s src/cli/headlessmanager.h -o org.qcma.HeadlessManager.
# Create the helper class # Create the helper class
DBUS_ADAPTORS = org.qcma.HeadlessManager.xml DBUS_ADAPTORS = org.qcma.HeadlessManager.xml

View File

@@ -65,3 +65,14 @@ unix:!macx {
HEADERS += src/kdenotifier.h 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
}

View File

@@ -45,6 +45,7 @@ void ClientManager::databaseUpdated(int count)
} else { } else {
emit messageSent(tr("Database indexing aborted by user")); emit messageSent(tr("Database indexing aborted by user"));
} }
emit updated(count);
} }
void ClientManager::showPinDialog(QString name, int pin) void ClientManager::showPinDialog(QString name, int pin)

View File

@@ -50,15 +50,18 @@ private:
QThread *wireless_thread; QThread *wireless_thread;
signals: signals:
void updated(int);
void stopped(); void stopped();
void receivedPin(int); void receivedPin(int);
void deviceDisconnected(); void deviceDisconnected();
void messageSent(QString); void messageSent(QString);
void deviceConnected(QString); void deviceConnected(QString);
public slots:
void refreshDatabase();
private slots: private slots:
void threadStopped(); void threadStopped();
void refreshDatabase();
void databaseUpdated(int count); void databaseUpdated(int count);
void showPinDialog(QString name, int pin); void showPinDialog(QString name, int pin);
}; };

View File

@@ -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 //TODO: check if this is actually needed since we don't have a main window by default
QApplication::setQuitOnLastWindowClosed(false); QApplication::setQuitOnLastWindowClosed(false);
bool showSystray = app.arguments().contains("--no-systray");
MainWidget widget; MainWidget widget;
widget.prepareApplication(); widget.prepareApplication(showSystray);
// receive the message from another process // receive the message from another process
QObject::connect(&app, SIGNAL(messageAvailable(QString)), &widget, SLOT(receiveMessage(QString))); QObject::connect(&app, SIGNAL(messageAvailable(QString)), &widget, SLOT(receiveMessage(QString)));

View File

@@ -21,6 +21,10 @@
#include "cmaclient.h" #include "cmaclient.h"
#include "cmautils.h" #include "cmautils.h"
#ifdef Q_OS_LINUX
#include "clientmanager_adaptor.h"
#endif
#include "qlistdb.h" #include "qlistdb.h"
#include "sqlitedb.h" #include "sqlitedb.h"
@@ -44,10 +48,32 @@ const QStringList MainWidget::path_list = QStringList() << "photoPath" << "music
bool sleptOnce = false; 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) : MainWidget::MainWidget(QWidget *parent) :
QWidget(parent), db(NULL), configForm(NULL), managerForm(NULL), backupForm(NULL) QWidget(parent), db(NULL), configForm(NULL), managerForm(NULL), backupForm(NULL)
{ {
#ifndef ENABLE_KDE_NOTIFIER
trayIcon = NULL;
#else
notifierItem = NULL;
#endif
} }
#endif
void MainWidget::checkSettings() void MainWidget::checkSettings()
{ {
@@ -101,7 +127,7 @@ void MainWidget::deviceDisconnect()
receiveMessage(tr("The device has been disconnected")); receiveMessage(tr("The device has been disconnected"));
} }
void MainWidget::deviceConnected(QString message) void MainWidget::deviceConnect(QString message)
{ {
#ifndef ENABLE_KDE_NOTIFIER #ifndef ENABLE_KDE_NOTIFIER
#ifndef Q_OS_WIN32 #ifndef Q_OS_WIN32
@@ -117,7 +143,7 @@ void MainWidget::deviceConnected(QString message)
receiveMessage(message); receiveMessage(message);
} }
void MainWidget::prepareApplication() void MainWidget::prepareApplication(bool showSystray)
{ {
//TODO: delete database before exit //TODO: delete database before exit
if(QSettings().value("useMemoryStorage", true).toBool()) { if(QSettings().value("useMemoryStorage", true).toBool()) {
@@ -130,7 +156,11 @@ void MainWidget::prepareApplication()
backupForm = new BackupManagerForm(db, this); backupForm = new BackupManagerForm(db, this);
managerForm = new ClientManager(db, this); managerForm = new ClientManager(db, this);
connectSignals(); connectSignals();
if(showSystray) {
createTrayIcon(); createTrayIcon();
}
checkSettings(); checkSettings();
} }
@@ -138,19 +168,22 @@ void MainWidget::connectSignals()
{ {
connect(configForm, SIGNAL(finished(int)), this, SLOT(dialogResult(int))); connect(configForm, SIGNAL(finished(int)), this, SLOT(dialogResult(int)));
connect(managerForm, SIGNAL(stopped()), qApp, SLOT(quit())); connect(managerForm, SIGNAL(stopped()), qApp, SLOT(quit()));
connect(managerForm, SIGNAL(deviceConnected(QString)), this, SLOT(deviceConnected(QString))); connect(managerForm, SIGNAL(deviceConnected(QString)), this, SIGNAL(deviceConnected(QString)));
connect(managerForm, SIGNAL(deviceDisconnected()), this, SLOT(deviceDisconnect())); connect(managerForm, SIGNAL(deviceDisconnected()), this, SIGNAL(deviceDisconnected()));
connect(managerForm, SIGNAL(messageSent(QString)), this, SLOT(receiveMessage(QString))); connect(managerForm, SIGNAL(messageSent(QString)), this, SIGNAL(messageReceived(QString)));
connect(managerForm, SIGNAL(updated(int)), this, SIGNAL(databaseUpdated(int)));
//backupForm.db = managerForm.db;
} }
void MainWidget::setTrayTooltip(QString message) void MainWidget::setTrayTooltip(QString message)
{ {
#ifndef ENABLE_KDE_NOTIFIER #ifndef ENABLE_KDE_NOTIFIER
if(trayIcon) {
trayIcon->setToolTip(message); trayIcon->setToolTip(message);
}
#else #else
if(notifierItem) {
notifierItem->setToolTipSubTitle(message); notifierItem->setToolTipSubTitle(message);
}
#endif #endif
} }
@@ -189,6 +222,16 @@ void MainWidget::showAboutQt()
QMessageBox::aboutQt(this); QMessageBox::aboutQt(this);
} }
void MainWidget::openConfig()
{
configForm->open();
}
void MainWidget::refreshDatabase()
{
managerForm->refreshDatabase();
}
void MainWidget::createTrayIcon() void MainWidget::createTrayIcon()
{ {
options = new QAction(tr("&Settings"), this); options = new QAction(tr("&Settings"), this);
@@ -198,9 +241,9 @@ void MainWidget::createTrayIcon()
about_qt = new QAction(tr("Abou&t Qt"), this); about_qt = new QAction(tr("Abou&t Qt"), this);
quit = new QAction(tr("&Quit"), 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(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, SIGNAL(triggered()), this, SLOT(showAboutDialog()));
connect(about_qt, SIGNAL(triggered()), this, SLOT(showAboutQt())); connect(about_qt, SIGNAL(triggered()), this, SLOT(showAboutQt()));
connect(quit, SIGNAL(triggered()), this, SLOT(stopServer())); connect(quit, SIGNAL(triggered()), this, SLOT(stopServer()));
@@ -241,6 +284,10 @@ void MainWidget::createTrayIcon()
notifierItem->setToolTipSubTitle(tr("Disconnected")); notifierItem->setToolTipSubTitle(tr("Disconnected"));
notifierItem->setStandardActionsEnabled(false); notifierItem->setStandardActionsEnabled(false);
#endif #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) void MainWidget::receiveMessage(QString message)
@@ -265,7 +312,9 @@ void MainWidget::receiveMessage(QString message)
MainWidget::~MainWidget() MainWidget::~MainWidget()
{ {
#ifndef ENABLE_KDE_NOTIFIER #ifndef ENABLE_KDE_NOTIFIER
if(trayIcon) {
trayIcon->hide(); trayIcon->hide();
}
#endif #endif
delete db; delete db;
} }

View File

@@ -34,16 +34,22 @@
#include "kdenotifier.h" #include "kdenotifier.h"
#endif #endif
#ifdef Q_OS_LINUX
#include <QDBusConnection>
#endif
#include <vitamtp.h> #include <vitamtp.h>
class MainWidget : public QWidget class MainWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.qcma.ClientManager")
public: public:
explicit MainWidget(QWidget *parent = 0); explicit MainWidget(QWidget *parent = 0);
~MainWidget(); ~MainWidget();
void prepareApplication(); void prepareApplication(bool showSystray);
private: private:
void connectSignals(); void connectSignals();
@@ -68,6 +74,10 @@ private:
QAction *about; QAction *about;
QAction *about_qt; QAction *about_qt;
#ifdef Q_OS_LINUX
QDBusConnection dbus_conn;
#endif
#ifndef ENABLE_KDE_NOTIFIER #ifndef ENABLE_KDE_NOTIFIER
QSystemTrayIcon *trayIcon; QSystemTrayIcon *trayIcon;
#else #else
@@ -76,12 +86,22 @@ private:
const static QStringList path_list; const static QStringList path_list;
private slots: signals:
void stopServer(); 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 openManager();
void showAboutQt(); void showAboutQt();
void showAboutDialog(); void showAboutDialog();
void deviceConnected(QString message); void refreshDatabase();
void stopServer();
private slots:
void deviceConnect(QString message);
void deviceDisconnect(); void deviceDisconnect();
void dialogResult(int result); void dialogResult(int result);
void receiveMessage(QString message); void receiveMessage(QString message);

View File

@@ -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 SQLiteDB::insertObjectEntryInternal(const QString &path, const QString &name, int parent_ohfi, int root_ohfi)
{ {
int ohfi; int ohfi = 0;
QFileInfo info(path, name); QFileInfo info(path, name);
if(info.isDir()) { if(info.isDir()) {