Skip to content

Commit

Permalink
Merge pull request #3 from thp/inactivity-timeout
Browse files Browse the repository at this point in the history
[nemo] Implement 1-minute inactivity timeout
  • Loading branch information
thp committed Oct 22, 2013
2 parents 22f6f9f + 3fdc77a commit 163c834
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/passwordmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,17 @@ PasswordManager::OBJECT_PATH = "/org/nemo/passwordmanager";
PasswordManager::PasswordManager(QObject *parent)
: QObject(parent)
, store()
, autoclose()
{
// Inactivity timeout after which the service quits to save resources
const int AUTOCLOSE_TIMEOUT_MS = 60 * 1000;

// Configure auto-close timer to quit the service after inactivity
autoclose.setSingleShot(true);
autoclose.setInterval(AUTOCLOSE_TIMEOUT_MS);
QObject::connect(&autoclose, SIGNAL(timeout()),
this, SLOT(quit()));

QDBusConnection connection = QDBusConnection::systemBus();
if (!connection.registerService(SERVICE_NAME)) {
qFatal("Cannot register D-Bus service at %s", SERVICE_NAME);
Expand All @@ -48,6 +58,10 @@ PasswordManager::PasswordManager(QObject *parent)
}

new PasswordManagerAdaptor(this);

// Every time a client action is carried out, we call autoclose.start() to
// reset the timer. Do it here for the first time.
autoclose.start();
}

PasswordManager::~PasswordManager()
Expand All @@ -72,11 +86,14 @@ PasswordManager::generatePassword()
} else {
emit error(message);
}

autoclose.start();
}

QString
PasswordManager::getGeneratedPassword()
{
autoclose.start();
return store.get();
}

Expand All @@ -101,6 +118,8 @@ PasswordManager::setPassword(const QString &password)
} else {
emit error(message);
}

autoclose.start();
}

bool
Expand Down
2 changes: 2 additions & 0 deletions src/passwordmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <QObject>
#include <QString>
#include <QTimer>

#include "passwordmanager_store.h"

Expand Down Expand Up @@ -52,6 +53,7 @@ class PasswordManager : public QObject {

private:
PasswordManagerStore store;
QTimer autoclose;
};

#endif /* ORG_NEMO_PASSWORDMANAGER_H */

0 comments on commit 163c834

Please sign in to comment.