Use pkg-config to find ncursesw
[centerim5.git] / src / Notify.h
blobffd65ea4245d0deb5772ce4406e10915b12517aa
1 // Copyright (C) 2010-2015 Petr Pavlu <setup@dagobah.cz>
2 //
3 // This file is part of CenterIM.
4 //
5 // CenterIM is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // CenterIM is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with CenterIM. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef NOTIFY_H
19 #define NOTIFY_H
21 #include <cppconsui/MessageDialog.h>
22 #include <cppconsui/SplitDialog.h>
23 #include <cppconsui/TreeView.h>
24 #include <libpurple/purple.h>
26 #define NOTIFY (Notify::instance())
28 class Notify {
29 public:
30 static Notify *instance();
32 private:
33 class UserInfoDialog : public CppConsUI::SplitDialog {
34 public:
35 UserInfoDialog(const char *title);
36 virtual ~UserInfoDialog() override {}
38 // Window
39 virtual void onScreenResized() override;
41 void update(
42 PurpleConnection *gc, const char *who, PurpleNotifyUserInfo *user_info);
44 protected:
45 CppConsUI::TreeView *treeview_;
47 private:
48 CONSUI_DISABLE_COPY(UserInfoDialog);
51 typedef std::set<CppConsUI::AbstractDialog *> Notifications;
52 typedef std::pair<PurpleAccount *, std::string> User;
53 typedef std::map<User, UserInfoDialog *> UserInfos;
55 // Track all opened notifications so it is possible to break the
56 // purple_notify_close() -> AbstractDialog::Close() -> purple_notify_close()
57 // -> etc. loop.
58 Notifications notifications_;
59 // Keep track of all opened user info dialogs so they can be updated when
60 // notify_userinfo() is called for them several times.
61 UserInfos user_infos_;
63 PurpleNotifyUiOps centerim_notify_ui_ops_;
65 static Notify *my_instance_;
67 Notify();
68 ~Notify();
69 CONSUI_DISABLE_COPY(Notify);
71 static void init();
72 static void finalize();
73 friend class CenterIM;
75 void onDialogClose(CppConsUI::Window &activator, PurpleNotifyType type);
76 void onUserInfoDialogClose(CppConsUI::Window &activator, User user);
78 static void *notify_message_(PurpleNotifyMsgType type, const char *title,
79 const char *primary, const char *secondary)
81 return NOTIFY->notify_message(type, title, primary, secondary);
83 static void *notify_userinfo_(
84 PurpleConnection *gc, const char *who, PurpleNotifyUserInfo *user_info)
86 return NOTIFY->notify_userinfo(gc, who, user_info);
88 static void close_notify_(PurpleNotifyType type, void *ui_handle)
90 NOTIFY->close_notify(type, ui_handle);
93 void *notify_message(PurpleNotifyMsgType type, const char *title,
94 const char *primary, const char *secondary);
95 void *notify_userinfo(
96 PurpleConnection *gc, const char *who, PurpleNotifyUserInfo *user_info);
97 void close_notify(PurpleNotifyType type, void *ui_handle);
100 #endif // NOTIFY_H
102 // vim: set tabstop=2 shiftwidth=2 textwidth=80 expandtab: