libqutim 0.2.80.1
|
00001 /**************************************************************************** 00002 ** 00003 ** qutIM - instant messenger 00004 ** 00005 ** Copyright © 2011 Aleksey Sidorov <gorthauer87@yandex.ru> 00006 ** 00007 ***************************************************************************** 00008 ** 00009 ** $QUTIM_BEGIN_LICENSE$ 00010 ** This program is free software: you can redistribute it and/or modify 00011 ** it under the terms of the GNU General Public License as published by 00012 ** the Free Software Foundation, either version 3 of the License, or 00013 ** (at your option) any later version. 00014 ** 00015 ** This program is distributed in the hope that it will be useful, 00016 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00018 ** See the GNU General Public License for more details. 00019 ** 00020 ** You should have received a copy of the GNU General Public License 00021 ** along with this program. If not, see http://www.gnu.org/licenses/. 00022 ** $QUTIM_END_LICENSE$ 00023 ** 00024 ****************************************************************************/ 00025 00026 #ifndef NOTIFICATION_H 00027 #define NOTIFICATION_H 00028 00029 #include "libqutim_global.h" 00030 #include "actiongenerator.h" 00031 #include <QIcon> 00032 00033 namespace qutim_sdk_0_3 00034 { 00035 00036 class NotificationBackend; 00037 class NotificationPrivate; 00038 class NotificationRequest; 00039 class NotificationRequestPrivate; 00040 class NotificationActionPrivate; 00041 class NotificationBackendPrivate; 00042 class Message; 00043 class Status; 00044 class Buddy; 00045 00046 class LIBQUTIM_EXPORT Notification : public QObject 00047 { 00048 Q_OBJECT 00049 Q_DECLARE_PRIVATE(Notification) 00050 Q_ENUMS(Type) 00051 public: 00052 typedef QSharedPointer<Notification> Ptr; //FIXME find usable pointer! 00053 enum Type 00054 { 00055 IncomingMessage, 00056 OutgoingMessage, 00057 AppStartup, 00058 BlockedMessage, 00059 ChatUserJoined, 00060 ChatUserLeft, 00061 ChatIncomingMessage, 00062 ChatOutgoingMessage, 00063 FileTransferCompleted, 00064 UserOnline, 00065 UserOffline, 00066 UserChangedStatus, 00067 UserHasBirthday, 00068 UserTyping, 00069 System, 00070 LastType = System 00071 }; 00072 enum State 00073 { 00074 Active, 00075 Accepted, 00076 Ignored, 00077 Rejected 00078 }; 00079 static Notification *send(const Message &msg); 00080 static Notification *send(const QString &text); 00081 ~Notification(); 00082 NotificationRequest request() const; 00083 State state(); 00084 static LocalizedString typeString(Type type); 00085 static LocalizedStringList typeStrings(); 00086 static LocalizedString descriptionString(Type type); 00087 static LocalizedStringList descriptionStrings(); 00088 public slots: 00089 void accept(); 00090 void ignore(); 00091 void reject(); 00092 signals: 00093 void accepted(); 00094 void ignored(); 00095 void rejected(); 00096 void finished(qutim_sdk_0_3::Notification::State state); 00097 protected: 00098 Notification(const NotificationRequest &request); 00099 QScopedPointer<NotificationPrivate> d_ptr; 00100 friend class NotificationRequest; 00101 friend class NotificationBackend; 00102 }; 00103 typedef QList<Notification*> NotificationList; 00104 00105 class LIBQUTIM_EXPORT NotificationAction 00106 { 00107 public: 00108 enum Type 00109 { 00110 AcceptButton, 00111 IgnoreButton, 00112 AdditionalButton 00113 }; 00114 00115 NotificationAction(); 00116 NotificationAction(const QIcon &icon, const LocalizedString &title, 00117 QObject *receiver, const char *method); 00118 NotificationAction(const LocalizedString &title, 00119 QObject *receiver, const char *method); 00120 NotificationAction(const NotificationAction &action); 00121 ~NotificationAction(); 00122 const NotificationAction &operator=(const NotificationAction &rhs); 00123 QIcon icon() const; 00124 LocalizedString title() const; 00125 Type type() const; 00126 void setType(Type type); 00127 QObject *receiver() const; 00128 const char *method() const; 00129 void trigger() const; 00130 private: 00131 friend class Notification; 00132 QSharedDataPointer<NotificationActionPrivate> d; 00133 }; 00134 00135 class LIBQUTIM_EXPORT NotificationRequest 00136 { 00137 public: 00138 NotificationRequest(); 00139 NotificationRequest(const Message &msg); 00140 NotificationRequest(Notification::Type type); 00141 NotificationRequest(Buddy *buddy, const Status &status, const Status &previous); 00142 NotificationRequest(const NotificationRequest &other); 00143 ~NotificationRequest(); 00144 NotificationRequest &operator =(const NotificationRequest &other); 00147 Notification *send(); 00148 void setObject(QObject *obj); 00149 QObject *object() const; 00150 void setImage(const QPixmap &pixmap); 00151 QPixmap image() const; 00152 void setTitle(const QString &title); 00153 QString title() const; 00154 void setText(const QString &text); 00155 QString text() const; 00156 void setType(Notification::Type type); 00157 Notification::Type type() const; 00158 void reject(const QByteArray &reason); 00159 QSet<QByteArray> rejectionReasons() const; 00160 void setBackends(const QSet<QByteArray> &backendTypes); 00161 void blockBackend(const QByteArray &backendType); 00162 void unblockBackend(const QByteArray &backendType); 00163 bool isBackendBlocked(const QByteArray &backendType); 00164 QVariant property(const char *name, const QVariant &def) const; 00165 template<typename T> 00166 T property(const char *name, const T &def) const 00167 { return qVariantValue<T>(property(name, qVariantFromValue<T>(def))); } 00168 void setProperty(const char *name, const QVariant &value); 00169 void addAction(const NotificationAction &action); 00170 static void addAction(Notification::Type type, const NotificationAction &action); 00171 QList<NotificationAction> actions() const; 00172 private: 00173 friend class Notification; 00174 QSharedDataPointer<NotificationRequestPrivate> d_ptr; 00175 }; 00176 00177 class LIBQUTIM_EXPORT NotificationFilter 00178 { 00179 public: 00180 enum Priority 00181 { 00182 LowPriority = 0x00000100, 00183 NormalPriortity = 0x00010000, 00184 HighPriority = 0x01000000 00185 }; 00186 virtual ~NotificationFilter(); 00187 00188 static void registerFilter(NotificationFilter *handler, 00189 int priority = NormalPriortity); 00190 static void unregisterFilter(NotificationFilter *handler); 00191 protected: 00192 friend class NotificationRequest; 00193 virtual void filter(NotificationRequest &request) = 0; 00194 virtual void notificationCreated(Notification *notification); 00195 virtual void virtual_hook(int id, void *data); 00196 }; 00197 00198 class LIBQUTIM_EXPORT NotificationBackend 00199 { 00200 Q_DECLARE_PRIVATE(NotificationBackend) 00201 public: 00202 NotificationBackend(const QByteArray &type); 00203 virtual ~NotificationBackend(); 00204 //TODO rewrite on Notification::Ptr 00205 virtual void handleNotification(Notification *notification) = 0; 00206 QByteArray backendType() const; 00207 LocalizedString description() const; 00208 static QList<QByteArray> allTypes(); 00209 static NotificationBackend* get(const QByteArray &type); 00210 static QList<NotificationBackend*> all(); 00211 protected: 00212 void ref(Notification *notification); 00213 void deref(Notification *notification); 00214 void setDescription(const LocalizedString &description); 00215 void allowRejectedNotifications(const QByteArray &reason); 00216 virtual void virtual_hook(int id, void *data); 00217 private: 00218 friend class NotificationRequest; 00219 QScopedPointer<NotificationBackendPrivate> d_ptr; 00220 }; 00221 00222 class LIBQUTIM_EXPORT NotificationManager : public QObject 00223 { 00224 Q_OBJECT 00225 public: 00226 static NotificationManager *instance(); 00227 static void setBackendState(const QByteArray &type, bool enabled); 00228 static void enableBackend(const QByteArray &type); 00229 static void disableBackend(const QByteArray &type); 00230 static bool isBackendEnabled(const QByteArray &type); 00231 signals: 00232 void backendCreated(const QByteArray &type, qutim_sdk_0_3::NotificationBackend *backend); 00233 void backendDestroyed(const QByteArray &type, qutim_sdk_0_3::NotificationBackend *backend); 00234 void backendStateChanged(const QByteArray &type, bool enabled); 00235 private: 00236 friend class NotificationBackend; 00237 NotificationManager(); 00238 }; 00239 00240 } // namespace qutim_sdk_0_3 00241 00242 Q_DECLARE_METATYPE(qutim_sdk_0_3::Notification*) 00243 Q_DECLARE_METATYPE(qutim_sdk_0_3::NotificationRequest) 00244 Q_DECLARE_METATYPE(qutim_sdk_0_3::NotificationAction) 00245 Q_DECLARE_METATYPE(qutim_sdk_0_3::NotificationBackend*) 00246 Q_DECLARE_INTERFACE(qutim_sdk_0_3::NotificationFilter, "org.qutim.core.NotificationFilter") 00247 00248 #endif // NOTIFICATION_H 00249