Home · All Classes · Main Classes · Deprecated

mnotification.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation (directui@nokia.com)
00006 **
00007 ** This file is part of libmeegotouch.
00008 **
00009 ** If you have questions regarding the use of this file, please contact
00010 ** Nokia at directui@nokia.com.
00011 **
00012 ** This library is free software; you can redistribute it and/or
00013 ** modify it under the terms of the GNU Lesser General Public
00014 ** License version 2.1 as published by the Free Software Foundation
00015 ** and appearing in the file LICENSE.LGPL included in the packaging
00016 ** of this file.
00017 **
00018 ****************************************************************************/
00019 
00020 #include "mnotification.h"
00021 #include "mnotification_p.h"
00022 #include "mnotificationmanager.h"
00023 #include "mnotificationgroup.h"
00024 #include "mremoteaction.h"
00025 
00026 const QString MNotification::DeviceEvent = "device";
00027 const QString MNotification::DeviceAddedEvent = "device.added";
00028 const QString MNotification::DeviceErrorEvent = "device.error";
00029 const QString MNotification::DeviceRemovedEvent = "device.removed";
00030 const QString MNotification::EmailEvent = "email";
00031 const QString MNotification::EmailArrivedEvent = "email.arrived";
00032 const QString MNotification::EmailBouncedEvent = "email.bounced";
00033 const QString MNotification::ImEvent = "im";
00034 const QString MNotification::ImErrorEvent = "im.error";
00035 const QString MNotification::ImReceivedEvent = "im.received";
00036 const QString MNotification::NetworkEvent = "network";
00037 const QString MNotification::NetworkConnectedEvent = "network.connected";
00038 const QString MNotification::NetworkDisconnectedEvent = "network.disconnected";
00039 const QString MNotification::NetworkErrorEvent = "network.error";
00040 const QString MNotification::PresenceEvent = "presence";
00041 const QString MNotification::PresenceOfflineEvent = "presence.offline";
00042 const QString MNotification::PresenceOnlineEvent = "presence.online";
00043 const QString MNotification::TransferEvent = "transfer";
00044 const QString MNotification::TransferCompleteEvent = "transfer.complete";
00045 const QString MNotification::TransferErrorEvent = "transfer.error";
00046 const QString MNotification::MessageEvent = "x-nokia.message";
00047 const QString MNotification::MessageArrivedEvent = "x-nokia.message.arrived";
00048 
00049 MNotificationPrivate::MNotificationPrivate() :
00050     id(0),
00051     groupId(0),
00052     count(1)
00053 {
00054 }
00055 
00056 MNotificationPrivate::~MNotificationPrivate()
00057 {
00058 }
00059 
00060 
00061 MNotification::MNotification(MNotificationPrivate &dd) :
00062     d_ptr(&dd)
00063 {
00064 }
00065 
00066 MNotification::MNotification() :
00067     d_ptr(new MNotificationPrivate)
00068 {
00069 }
00070 
00071 MNotification::MNotification(const QString &eventType, const QString &summary, const QString &body) :
00072     d_ptr(new MNotificationPrivate)
00073 {
00074     Q_D(MNotification);
00075     d->eventType = eventType;
00076     d->summary = summary;
00077     d->body = body;
00078 }
00079 
00080 MNotification::MNotification(const MNotification &notification) :
00081     QObject(), d_ptr(new MNotificationPrivate)
00082 {
00083     *this = notification;
00084 }
00085 
00086 MNotification::MNotification(uint id) :
00087     d_ptr(new MNotificationPrivate)
00088 {
00089     Q_D(MNotification);
00090     d->id = id;
00091 }
00092 
00093 MNotification::~MNotification()
00094 {
00095     delete d_ptr;
00096 }
00097 
00098 uint MNotification::id() const
00099 {
00100     Q_D(const MNotification);
00101     return d->id;
00102 }
00103 
00104 void MNotification::setGroup(const MNotificationGroup &group)
00105 {
00106     Q_D(MNotification);
00107     d->groupId = group.id();
00108 }
00109 
00110 void MNotification::setEventType(const QString &eventType)
00111 {
00112     Q_D(MNotification);
00113     d->eventType = eventType;
00114 }
00115 
00116 QString MNotification::eventType() const
00117 {
00118     Q_D(const MNotification);
00119     return d->eventType;
00120 }
00121 
00122 void MNotification::setSummary(const QString &summary)
00123 {
00124     Q_D(MNotification);
00125     d->summary = summary;
00126 }
00127 
00128 QString MNotification::summary() const
00129 {
00130     Q_D(const MNotification);
00131     return d->summary;
00132 }
00133 
00134 void MNotification::setBody(const QString &body)
00135 {
00136     Q_D(MNotification);
00137     d->body = body;
00138 }
00139 
00140 QString MNotification::body() const
00141 {
00142     Q_D(const MNotification);
00143     return d->body;
00144 }
00145 
00146 void MNotification::setImage(const QString &image)
00147 {
00148     Q_D(MNotification);
00149     d->image = image;
00150 }
00151 
00152 QString MNotification::image() const
00153 {
00154     Q_D(const MNotification);
00155     return d->image;
00156 }
00157 
00158 void MNotification::setAction(const MRemoteAction &action)
00159 {
00160     Q_D(MNotification);
00161     d->action = action.toString();
00162 }
00163 
00164 void MNotification::setCount(uint count)
00165 {
00166     Q_D(MNotification);
00167     d->count = count;
00168 }
00169 
00170 uint MNotification::count() const
00171 {
00172     Q_D(const MNotification);
00173     return d->count;
00174 }
00175 
00176 bool MNotification::publish()
00177 {
00178     Q_D(MNotification);
00179 
00180     bool success = false;
00181     if (d->id == 0) {
00182         if (!d->summary.isNull() || !d->body.isNull() || !d->image.isNull() || !d->action.isNull()) {
00183             d->id = MNotificationManager::instance()->addNotification(d->groupId, d->eventType, d->summary, d->body, d->action, d->image, d->count);
00184         } else {
00185             d->id = MNotificationManager::instance()->addNotification(d->groupId, d->eventType);
00186         }
00187 
00188         success = d->id != 0;
00189     } else {
00190         if (!d->summary.isNull() || !d->body.isNull() || !d->image.isNull() || !d->action.isNull()) {
00191             success = MNotificationManager::instance()->updateNotification(d->id, d->eventType, d->summary, d->body, d->action, d->image, d->count);
00192         } else {
00193             success = MNotificationManager::instance()->updateNotification(d->id, d->eventType);
00194         }
00195     }
00196 
00197     return success;
00198 }
00199 
00200 bool MNotification::remove()
00201 {
00202     bool success = false;
00203 
00204     if (isPublished()) {
00205         Q_D(MNotification);
00206         uint id = d->id;
00207         d->id = 0;
00208         success = MNotificationManager::instance()->removeNotification(id);
00209     }
00210 
00211     return success;
00212 }
00213 
00214 bool MNotification::isPublished() const
00215 {
00216     Q_D(const MNotification);
00217     return d->id != 0;
00218 }
00219 
00220 QList<MNotification *> MNotification::notifications()
00221 {
00222     QList<MNotification> list = MNotificationManager::instance()->notificationList();
00223     QList<MNotification *> notifications;
00224     foreach(const MNotification &notification, list) {
00225         notifications.append(new MNotification(notification));
00226     }
00227     return notifications;
00228 }
00229 
00230 QDBusArgument &operator<<(QDBusArgument &argument, const MNotification &notification)
00231 {
00232     const MNotificationPrivate *d = notification.d_func();
00233     argument.beginStructure();
00234     argument << d->id;
00235     argument << d->groupId;
00236     argument << d->eventType;
00237     argument << d->summary;
00238     argument << d->body;
00239     argument << d->image;
00240     argument << d->action;
00241     argument << d->count;
00242     argument.endStructure();
00243     return argument;
00244 }
00245 
00246 const QDBusArgument &operator>>(const QDBusArgument &argument, MNotification &notification)
00247 {
00248     MNotificationPrivate *d = notification.d_func();
00249     argument.beginStructure();
00250     argument >> d->id;
00251     argument >> d->groupId;
00252     argument >> d->eventType;
00253     argument >> d->summary;
00254     argument >> d->body;
00255     argument >> d->image;
00256     argument >> d->action;
00257     argument >> d->count;
00258     argument.endStructure();
00259     return argument;
00260 }
00261 
00262 MNotification &MNotification::operator=(const MNotification &notification)
00263 {
00264     Q_D(MNotification);
00265     const MNotificationPrivate *dn = notification.d_func();
00266     d->id = dn->id;
00267     d->groupId = dn->groupId;
00268     d->eventType = dn->eventType;
00269     d->summary = dn->summary;
00270     d->body = dn->body;
00271     d->image = dn->image;
00272     d->action = dn->action;
00273     d->count = dn->count;
00274     return *this;
00275 }

Copyright © 2010 Nokia Corporation Generated on Thu Nov 4 2010 18:14:21 (PDT)
Doxygen 1.7.1
MeeGo Touch