Skip to content

Commit

Permalink
Merge pull request #31 from matthewvogt/remove-mnotification
Browse files Browse the repository at this point in the history
Remove mnotification
  • Loading branch information
matthewvogt committed Mar 19, 2015
2 parents be3f447 + 8f7313d commit 05c1344
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 152 deletions.
6 changes: 6 additions & 0 deletions data/data.pro
@@ -0,0 +1,6 @@
TEMPLATE = aux

notification_categories.path = /usr/share/lipstick/notificationcategories
notification_categories.files = notificationcategories/*.conf

INSTALLS += notification_categories
2 changes: 2 additions & 0 deletions data/notificationcategories/x-nemo.transfer.complete.conf
@@ -0,0 +1,2 @@
appIcon=icon-lock-transfer
urgency=1
3 changes: 3 additions & 0 deletions data/notificationcategories/x-nemo.transfer.conf
@@ -0,0 +1,3 @@
appIcon=icon-lock-transfer
transient=true
urgency=1
2 changes: 2 additions & 0 deletions data/notificationcategories/x-nemo.transfer.error.conf
@@ -0,0 +1,2 @@
appIcon=icon-lock-transfer
urgency=2
10 changes: 3 additions & 7 deletions doc/doc.pri
@@ -1,14 +1,10 @@
equals(QT_MAJOR_VERSION, 4): QDOC = qdoc3
equals(QT_MAJOR_VERSION, 5): QDOC = qdoc
QDOC = qdoc
QHELPGENERATOR = qhelpgenerator
equals(QT_MAJOR_VERSION, 4): QDOCCONF = doc/config/transfer-engine-project.qdocconf
equals(QT_MAJOR_VERSION, 5): QDOCCONF = transfer-engine-project.qdocconf
QDOCCONF = transfer-engine-project.qdocconf
QHELPFILE = doc/html/transferengine.qhp
QCHFILE = doc/html/transferengine.qch

equals(QT_MAJOR_VERSION, 4): docs.commands = ($$QDOC $$QDOCCONF) && \
($$QHELPGENERATOR $$QHELPFILE -o $$QCHFILE)
equals(QT_MAJOR_VERSION, 5): docs.commands = (cd doc/config; $$QDOC $$QDOCCONF; cd ../..) && \
docs.commands = (cd doc/config; $$QDOC $$QDOCCONF; cd ../..) && \
($$QHELPGENERATOR $$QHELPFILE -o $$QCHFILE)

QMAKE_EXTRA_TARGETS += docs
Expand Down
18 changes: 6 additions & 12 deletions lib/lib.pro
@@ -1,12 +1,10 @@
TEMPLATE = lib
equals(QT_MAJOR_VERSION, 4): TARGET = nemotransferengine
equals(QT_MAJOR_VERSION, 5): TARGET = nemotransferengine-qt5
TARGET = nemotransferengine-qt5
DEPENDPATH += .
INCLUDEPATH += .
CONFIG += shared link_pkgconfig
QT += dbus
equals(QT_MAJOR_VERSION, 4): PKGCONFIG += quillmetadata
equals(QT_MAJOR_VERSION, 5): PKGCONFIG += quillmetadata-qt5
PKGCONFIG += quillmetadata-qt5

system(qdbusxml2cpp -v -c TransferEngineInterface -p transferengineinterface.h:transferengineinterface.cpp -i metatypedeclarations.h ../dbus/org.nemo.transferengine.xml)

Expand Down Expand Up @@ -38,22 +36,18 @@ HEADERS += \
SOURCES += \
transferengineinterface.cpp

equals(QT_MAJOR_VERSION, 4): OTHER_FILES += nemotransfernegine.pc nemotransferengine-plugin.prf
equals(QT_MAJOR_VERSION, 5): OTHER_FILES += nemotransfernegine-qt5.pc nemotransferengine-plugin-qt5.prf
OTHER_FILES += nemotransfernegine-qt5.pc nemotransferengine-plugin-qt5.prf

headers.files = $$HEADERS
equals(QT_MAJOR_VERSION, 4): headers.path = /usr/include/TransferEngine
equals(QT_MAJOR_VERSION, 5): headers.path = /usr/include/TransferEngine-qt5
headers.path = /usr/include/TransferEngine-qt5

target.path = /usr/lib

pkgconfigpc.path = /usr/lib/pkgconfig/
equals(QT_MAJOR_VERSION, 4): pkgconfigpc.files = nemotransferengine.pc
equals(QT_MAJOR_VERSION, 5): pkgconfigpc.files = nemotransferengine-qt5.pc
pkgconfigpc.files = nemotransferengine-qt5.pc

prf.path = $$[QT_INSTALL_DATA]/mkspecs/features
equals(QT_MAJOR_VERSION, 4): prf.files = nemotransferengine-plugin.prf
equals(QT_MAJOR_VERSION, 5): prf.files = nemotransferengine-plugin-qt5.prf
prf.files = nemotransferengine-plugin-qt5.prf


INSTALLS += target headers prf pkgconfigpc
4 changes: 2 additions & 2 deletions rpm/transfer-engine-qt5.spec
Expand Up @@ -14,8 +14,8 @@ BuildRequires: pkgconfig(Qt5Qml)
BuildRequires: pkgconfig(Qt5Quick)
BuildRequires: pkgconfig(accounts-qt5)
BuildRequires: desktop-file-utils
BuildRequires: pkgconfig(mlite5)
BuildRequires: pkgconfig(quillmetadata-qt5)
BuildRequires: pkgconfig(nemonotifications-qt5) >= 1.0.4
BuildRequires: qt5-qttools-linguist
BuildRequires: qt5-qttools-qthelp-devel
BuildRequires: qt5-plugin-platform-minimal
Expand All @@ -35,7 +35,7 @@ Obsoletes: nemo-transferengine <= 0.0.19
%{_bindir}/nemo-transfer-engine
%{_datadir}/dbus-1/services/org.nemo.transferengine.service
%{_datadir}/translations/nemo-transfer-engine_eng_en.qm

%{_datadir}/lipstick/notificationcategories/*

%package -n libnemotransferengine-qt5
Summary: Transfer engine library.
Expand Down
2 changes: 2 additions & 0 deletions src/main.cpp
Expand Up @@ -43,6 +43,8 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
translator.load(QLocale(), "nemo-transfer-engine", "-", translationPath);
app.installTranslator(&translator);

//% "Transfers"
app.setApplicationName(qtTrId("transferengine-ap-transfers"));

TransferEngine engine;
return app.exec();
Expand Down
6 changes: 2 additions & 4 deletions src/src.pro
Expand Up @@ -11,15 +11,13 @@ packagesExist(qt5-boostable) {
warning("qt5-boostable not available; startup times will be slower")
}

equals(QT_MAJOR_VERSION, 4): LIBS += -L../lib -lnemotransferengine
equals(QT_MAJOR_VERSION, 5): LIBS += -L../lib -lnemotransferengine-qt5
LIBS += -L../lib -lnemotransferengine-qt5

# generate adaptor code
system(qdbusxml2cpp -c TransferEngineAdaptor -a transferengineadaptor.h:transferengineadaptor.cpp -i metatypedeclarations.h ../dbus/org.nemo.transferengine.xml)

CONFIG += link_pkgconfig
equals(QT_MAJOR_VERSION, 4): PKGCONFIG += mlite accounts-qt
equals(QT_MAJOR_VERSION, 5): PKGCONFIG += mlite5 accounts-qt5
PKGCONFIG += accounts-qt5 nemonotifications-qt5

# translations
TS_FILE = $$OUT_PWD/nemo-transfer-engine.ts
Expand Down
194 changes: 79 additions & 115 deletions src/transferengine.cpp
Expand Up @@ -40,8 +40,7 @@
#include <QFileSystemWatcher>
#include <QTimer>

#include <MNotification>
#include <MNotificationGroup>
#include <notification.h>

#include <signal.h>

Expand All @@ -53,6 +52,10 @@
#define ACTIVITY_MONITOR_TIMEOUT 1*60*1000 // 1 minute in ms
#define TRANSFER_EXPIRATION_THRESHOLD 3*60 // 3 minutes in seconds

#define TRANSFER_EVENT_CATEGORY "x-nemo.transfer"
#define TRANSFER_COMPLETE_EVENT_CATEGORY "x-nemo.transfer.complete"
#define TRANSFER_ERROR_EVENT_CATEGORY "x-nemo.transfer.error"

TransferEngineSignalHandler * TransferEngineSignalHandler::instance()
{
static TransferEngineSignalHandler instance;
Expand Down Expand Up @@ -295,157 +298,135 @@ void TransferEnginePrivate::sendNotification(TransferEngineData::TransferType ty
return;
}

QString msgGSummary;
QString msgNBody;
QString eventType;
bool bannerOnly = false;
QString category;
QString body;
QString summary;
QString previewBody;
QString previewSummary;

QList<MNotification*> nList = MNotification::notifications();
QMultiMap <QString, MNotification*> nMap;
// TODO: explicit grouping of transfer notifications is now removed, as grouping
// will now be performed by lipstick. We may need to reinstate group summary
// notifications at some later point...

// Get the existing notifications and sort them based on their event types
foreach(MNotification *n, nList) {
nMap.insert(n->eventType(), n);
// Notification & Banner rules:
//
// Show Banner:
// - For succesfull uploads and for downloads
// - For failed Uploads, Downloads, Syncs
//
// Show an event in the EventView:
// - For downloads
// - For failed uploads, downloads and syncs

QList<QObject *> nList = Notification::notifications();
Notification *existing = 0;

foreach (QObject *obj, nList) {
if (Notification *n = qobject_cast<Notification *>(obj)) {
if (n->summary() == fileName || n->previewSummary() == fileName) {
// This existing notification is for this file
existing = n;
break;
}
}
}

if (status == TransferEngineData::TransferFinished) {
switch(type) {
case TransferEngineData::Upload:
//: Notification for successful file upload
//% "File uploaded"
msgNBody = qtTrId("transferengine-no-file-upload-success");
msgGSummary.clear();
eventType = MNotification::TransferEvent; // Use "generic" transfer event for uploads
bannerOnly = true;
previewBody = qtTrId("transferengine-no-file-upload-success");
previewSummary = fileName;
category = TRANSFER_EVENT_CATEGORY; // Use "generic" transfer event for uploads
break;
case TransferEngineData::Download:
eventType = MNotification::TransferCompleteEvent;
category = TRANSFER_COMPLETE_EVENT_CATEGORY;
//: Notification for successful file download
//% "File downloaded"
msgNBody = qtTrId("transferengine-no-file-download-success");
//: NotificationGroup summary for successful download
//% "%n file(s) downloaded"
msgGSummary = qtTrId("transferengine-no-number-of-downloads",
nMap.values(eventType).count() + 1);
body = qtTrId("transferengine-no-file-download-success");
summary = fileName;
break;
case TransferEngineData::Sync:
// Ok exit
return;
break;
default:
qWarning() << "TransferEnginePrivate::sendNotification: unknown state";
return;
break;
}
} else {
if (status == TransferEngineData::TransferInterrupted) {
eventType = MNotification::TransferErrorEvent;
category = TRANSFER_ERROR_EVENT_CATEGORY;

switch (type) {
case TransferEngineData::Upload:
//: Notification for failed file upload
//% "Upload failed!"
msgNBody = qtTrId("transferengine-no-file-upload-failure");
//% "%n upload(s) failed"
msgGSummary = qtTrId("transferengine-no-number-of-upload-failures",
nMap.values(eventType).count() + 1);
body = qtTrId("transferengine-no-file-upload-failure");
break;
case TransferEngineData::Download:
//: Notification for failed file download
//% "Download failed!"
msgNBody = qtTrId("transferengine-no-file-download-failure");
//% "%n download(s) failed"
msgGSummary = qtTrId("transferengine-no-number-of-download-failures",
nMap.values(eventType).count() + 1);
body = qtTrId("transferengine-no-file-download-failure");
break;
case TransferEngineData::Sync:
//: Notification for sync failure
//% "Sync failed!"
msgNBody = qtTrId("transferengine-no-sync-failure");
//% "%n sync(s) failed"
msgGSummary = qtTrId("transferengine-no-number-of-sync-failures",
nMap.values(eventType).count() + 1);
body = qtTrId("transferengine-no-sync-failure");
break;
default:
qWarning() << "TransferEnginePrivate::sendNotification: unknown state";
return;
category.clear();
break;
}


summary = fileName;
previewSummary = summary;
previewBody = body;
} else {
if (status == TransferEngineData::TransferCanceled) {
// Exit, no banners or events when user has canceled a transfer
return;
}}}

// Notification & Banner rules:
//
// Show Banner:
// - For succesfull uploads and for downloads
// - For failed Uploads, Downloads, Syncs
//
// Show an event in the EventView:
// - For downloads
// - For failed uploads, downloads and syncs
//
// Use grouping always
if (!(msgNBody.isEmpty() && eventType.isEmpty())) {
// First create the notification
MNotification notification(eventType);
notification.setSummary(fileName);
notification.setBody(msgNBody);
notification.setImage("icon-lock-transfer");


// Check if we have existing group and use that instead of creating a new one.
QList<MNotificationGroup*> groups = MNotificationGroup::notificationGroups();
MNotificationGroup *group = 0;
if (groups.count() > 0) {
foreach(MNotificationGroup *g, groups) {
if (g->eventType() == eventType) {
group = g;
break;
}
}
// Remove any existing notification
if (existing) {
existing->close();
}
}}}

// No existing groups, create a new one from the scratch
if (group == 0){
group = new MNotificationGroup(eventType);
group->setImage("icon-lock-transfer");
// Add to the groups, it will be deleted when the list is cleaned
groups.append(group);
}
if (!category.isEmpty()) {
Notification notification;

if (bannerOnly) {
// This makes notifications to appear banners only
group->setSummary(QString());
if (!existing) {
// Create a new notification
if (m_settings.status() != QSettings::NoError) {
qWarning() << Q_FUNC_INFO << "Failed to read settings!" << m_settings.status();
} else {
// This is the summary text which is shown when notifications are grouped
group->setSummary(msgGSummary);
group->setBody(fileName);
}
m_settings.beginGroup("transfers");
const QString service = m_settings.value("service").toString();
const QString path = m_settings.value("path").toString();
const QString iface = m_settings.value("interface").toString();
const QString method = m_settings.value("method").toString();
m_settings.endGroup();

// Set default action for groups
MRemoteAction rAct = createRemoteActionForGroup();
if (!rAct.toString().isEmpty()) {
group->setAction(rAct);
if (!service.isEmpty() && !path.isEmpty() && !iface.isEmpty() && !method.isEmpty()) {
notification.setRemoteAction(Notification::remoteAction("default", "", service, path, iface, method));
}
}

notification.setGroup(*group);
notification.publish();

// always publish the group to make updates appear
group->publish();
existing = &notification;
}

// Cleanup
if (groups.count()) {
qDeleteAll(groups);
// Update the notification
existing->setCategory(category);
existing->setSummary(summary);
existing->setBody(body);
existing->setPreviewSummary(previewSummary);
existing->setPreviewBody(previewBody);
existing->publish();
}

if (nList.count()) {
qDeleteAll(nList);
}
}
}

int TransferEnginePrivate::uploadMediaItem(MediaItem *mediaItem,
MediaTransferInterface *muif,
Expand Down Expand Up @@ -714,23 +695,6 @@ void TransferEnginePrivate::callbackCall(int transferId, CallbackMethodType meth
}


MRemoteAction TransferEnginePrivate::createRemoteActionForGroup()
{
if (m_settings.status() != QSettings::NoError) {
qWarning() << Q_FUNC_INFO << "Failed to read settings!" << m_settings.status();
return MRemoteAction();
}

m_settings.beginGroup("transfers");
const QString service = m_settings.value("service").toString();
const QString path = m_settings.value("path").toString();
const QString iface = m_settings.value("interface").toString();
const QString method = m_settings.value("method").toString();
m_settings.endGroup();

return MRemoteAction(service, path, iface, method);
}

/*!
\class TransferEngine
\brief The TransferEngine class implements the functionality for different transfer types.
Expand Down

0 comments on commit 05c1344

Please sign in to comment.