Code

init matrix variable, removes compiler warnings
[inkscape.git] / src / pedro / pedrogui.h
1 #ifndef __PEDROGUI_H__
2 #define __PEDROGUI_H__
3 /*
4  * Simple demo GUI for the Pedro mini-XMPP client.
5  *
6  * Authors:
7  *   Bob Jamison
8  *
9  * Copyright (C) 2005 Bob Jamison
10  *
11  *  This library is free software; you can redistribute it and/or
12  *  modify it under the terms of the GNU Lesser General Public
13  *  License as published by the Free Software Foundation; either
14  *  version 2.1 of the License, or (at your option) any later version.
15  *
16  *  This library is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  *  Lesser General Public License for more details.
20  *
21  *  You should have received a copy of the GNU Lesser General Public
22  *  License along with this library; if not, write to the Free Software
23  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24  */
28 #include <gtkmm.h>
30 #include "pedroxmpp.h"
33 namespace Pedro
34 {
37 class PedroGui;
38 class GroupChatWindow;
40 //#########################################################################
41 //# R O S T E R
42 //#########################################################################
43 class Roster : public Gtk::ScrolledWindow
44 {
45 public:
47     Roster()
48         { doSetup(); }
50     virtual ~Roster()
51         {}
53     /**
54      * Clear all roster items from the list
55      */
56     virtual void clear();
58     /**
59      * Regenerate the roster
60      */
61     virtual void refresh();
64     void setParent(PedroGui *val)
65         { parent = val; }
67 private:
69     class CustomTreeView : public Gtk::TreeView
70     {
71     public:
72         CustomTreeView()
73            { parent = NULL; }
74         virtual ~CustomTreeView()
75            {}
77         bool on_button_press_event(GdkEventButton* event)
78             {
79             Gtk::TreeView::on_button_press_event(event);
80             if (parent)
81                 parent->buttonPressCallback(event);
82             return true;
83             }
84         void setParent(Roster *val)
85             { parent = val; }
87     private:
88         Roster *parent;
89     };
91     void doubleClickCallback(const Gtk::TreeModel::Path &path,
92                    Gtk::TreeViewColumn *col);
94     void sendFileCallback();
95     void chatCallback();
96     bool buttonPressCallback(GdkEventButton* event);
98     bool doSetup();
100     Glib::RefPtr<Gdk::Pixbuf> pixbuf_available;
101     Glib::RefPtr<Gdk::Pixbuf> pixbuf_away;
102     Glib::RefPtr<Gdk::Pixbuf> pixbuf_chat;
103     Glib::RefPtr<Gdk::Pixbuf> pixbuf_dnd;
104     Glib::RefPtr<Gdk::Pixbuf> pixbuf_error;
105     Glib::RefPtr<Gdk::Pixbuf> pixbuf_offline;
106     Glib::RefPtr<Gdk::Pixbuf> pixbuf_xa;
107     
108     class RosterColumns : public Gtk::TreeModel::ColumnRecord
109     {
110     public:
111         RosterColumns()
112            {
113            add(groupColumn);
114            add(statusColumn); add(userColumn);
115            add(nameColumn);   add(subColumn);
116            }
118         Gtk::TreeModelColumn<Glib::ustring> groupColumn;
119         Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > statusColumn;
120         Gtk::TreeModelColumn<Glib::ustring> userColumn;
121         Gtk::TreeModelColumn<Glib::ustring> nameColumn;
122         Gtk::TreeModelColumn<Glib::ustring> subColumn;
123     };
125     RosterColumns rosterColumns;
127     Glib::RefPtr<Gtk::UIManager> uiManager;
129     Glib::RefPtr<Gtk::TreeStore> treeStore;
130     CustomTreeView rosterView;
132     PedroGui *parent;
133 };
135 //#########################################################################
136 //# M E S S A G E    L I S T
137 //#########################################################################
138 class MessageList : public Gtk::ScrolledWindow
140 public:
142     MessageList()
143         { doSetup(); }
145     virtual ~MessageList()
146         {}
148     /**
149      * Clear all messages from the list
150      */
151     virtual void clear();
153     /**
154      * Post a message to the list
155      */
156     virtual void postMessage(const DOMString &from, const DOMString &msg);
158 private:
160     bool doSetup();
162     Gtk::TextView messageList;
163     Glib::RefPtr<Gtk::TextBuffer> messageListBuffer;
165 };
167 //#########################################################################
168 //# U S E R    L I S T
169 //#########################################################################
170 class UserList : public Gtk::ScrolledWindow
172 public:
174     UserList()
175         { doSetup(); }
177     virtual ~UserList()
178         {}
180     /**
181      * Clear all messages from the list
182      */
183     virtual void clear();
185     /**
186      * Post a message to the list
187      */
188     virtual void addUser(const DOMString &user, const DOMString &show);
191     void setParent(GroupChatWindow *val)
192         { parent = val; }
194 private:
196     class CustomTreeView : public Gtk::TreeView
197     {
198     public:
199         CustomTreeView()
200            { parent = NULL; }
201         virtual ~CustomTreeView()
202            {}
204         bool on_button_press_event(GdkEventButton* event)
205             {
206             Gtk::TreeView::on_button_press_event(event);
207             if (parent)
208                 parent->buttonPressCallback(event);
209             return true;
210             }
211         void setParent(UserList *val)
212             { parent = val; }
214     private:
215         UserList *parent;
216     };
218     void doubleClickCallback(const Gtk::TreeModel::Path &path,
219                    Gtk::TreeViewColumn *col);
221     void sendFileCallback();
222     void chatCallback();
223     bool buttonPressCallback(GdkEventButton* event);
225     bool doSetup();
227     Glib::RefPtr<Gdk::Pixbuf> pixbuf_available;
228     Glib::RefPtr<Gdk::Pixbuf> pixbuf_away;
229     Glib::RefPtr<Gdk::Pixbuf> pixbuf_chat;
230     Glib::RefPtr<Gdk::Pixbuf> pixbuf_dnd;
231     Glib::RefPtr<Gdk::Pixbuf> pixbuf_error;
232     Glib::RefPtr<Gdk::Pixbuf> pixbuf_offline;
233     Glib::RefPtr<Gdk::Pixbuf> pixbuf_xa;
235     class UserListColumns : public Gtk::TreeModel::ColumnRecord
236     {
237     public:
238         UserListColumns()
239            { add(statusColumn); add(userColumn);  }
241         Gtk::TreeModelColumn<Glib::ustring> userColumn;
242         Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > statusColumn;
243     };
245     UserListColumns userListColumns;
247     Glib::RefPtr<Gtk::UIManager> uiManager;
249     Glib::RefPtr<Gtk::ListStore> userListStore;
250     CustomTreeView userList;
252     GroupChatWindow *parent;
253 };
256 //#########################################################################
257 //# C H A T    W I N D O W
258 //#########################################################################
259 class ChatWindow : public Gtk::Window
261 public:
263     ChatWindow(PedroGui &par, const DOMString jid);
265     virtual ~ChatWindow();
267     virtual DOMString getJid()
268         { return jid; }
270     virtual void setJid(const DOMString &val)
271         { jid = val; }
273     virtual bool postMessage(const DOMString &data);
275 private:
277     DOMString jid;
279     void leaveCallback();
280     void hideCallback();
281     void textEnterCallback();
283     bool doSetup();
285     Gtk::VBox   vbox;
286     Gtk::VPaned vPaned;
288     MessageList messageList;
290     Gtk::Entry inputTxt;
292     PedroGui &parent;
293 };
296 //#########################################################################
297 //# G R O U P    C H A T    W I N D O W
298 //#########################################################################
299 class GroupChatWindow : public Gtk::Window
301 public:
303     GroupChatWindow(PedroGui &par, const DOMString &groupJid,
304                                    const DOMString &nick);
306     virtual ~GroupChatWindow();
309     virtual DOMString getGroupJid()
310         { return groupJid; }
312     virtual void setGroupJid(const DOMString &val)
313         { groupJid = val; }
315     virtual DOMString getNick()
316         { return nick; }
318     virtual void setNick(const DOMString &val)
319         { nick = val; }
321     virtual bool receiveMessage(const DOMString &from,
322                                 const DOMString &data);
324     virtual bool receivePresence(const DOMString &nick,
325                                  bool presence,
326                                  const DOMString &show,
327                                  const DOMString &status);
329     virtual void doSendFile(const DOMString &nick);
331     virtual void doChat(const DOMString &nick);
334 private:
336     void textEnterCallback();
337     void leaveCallback();
338     void hideCallback();
340     bool doSetup();
342     Gtk::VBox   vbox;
343     Gtk::VPaned vPaned;
344     Gtk::HPaned hPaned;
346     MessageList messageList;
348     UserList userList;
350     Gtk::Entry inputTxt;
352     DOMString groupJid;
353     DOMString nick;
355     PedroGui &parent;
356  };
359 //#########################################################################
360 //# C O N N E C T    D I A L O G
361 //#########################################################################
362 class ConnectDialog : public Gtk::Dialog
364 public:
366     ConnectDialog(PedroGui &par) : parent(par)
367         { doSetup(); }
369     virtual ~ConnectDialog()
370         {}
372    DOMString getHost()
373        { return hostField.get_text(); }
374    int getPort()
375        { return (int)portSpinner.get_value(); }
376    DOMString getUser()
377        { return userField.get_text(); }
378    DOMString getPass()
379        { return passField.get_text(); }
380    DOMString getResource()
381        { return resourceField.get_text(); }
383 private:
385     void okCallback();
386     void cancelCallback();
388     bool doSetup();
390     Gtk::Table table;
392     Gtk::Label hostLabel;
393     Gtk::Entry hostField;
394     Gtk::Label portLabel;
395     Gtk::SpinButton portSpinner;
396     Gtk::Label userLabel;
397     Gtk::Entry userField;
398     Gtk::Label passLabel;
399     Gtk::Entry passField;
400     Gtk::Label resourceLabel;
401     Gtk::Entry resourceField;
403     PedroGui &parent;
404 };
408 //#########################################################################
409 //# C H A T   D I A L O G
410 //#########################################################################
411 class ChatDialog : public Gtk::Dialog
413 public:
415     ChatDialog(PedroGui &par) : parent(par)
416         { doSetup(); }
418     virtual ~ChatDialog()
419         {}
421    DOMString getUser()
422        { return userField.get_text(); }
424    DOMString getText()
425        { return textField.get_text(); }
427 private:
429     void okCallback();
430     void cancelCallback();
432     bool doSetup();
434     Gtk::Table table;
436     Gtk::Label userLabel;
437     Gtk::Entry userField;
438     Gtk::Entry textField;
440     PedroGui &parent;
441 };
445 //#########################################################################
446 //# G R O U P    C H A T   D I A L O G
447 //#########################################################################
449 class GroupChatDialog : public Gtk::Dialog
451 public:
453     GroupChatDialog(PedroGui &par) : parent(par)
454         { doSetup(); }
456     virtual ~GroupChatDialog()
457         {}
459    DOMString getGroup()
460        { return groupField.get_text(); }
461    DOMString getHost()
462        { return hostField.get_text(); }
463    DOMString getPass()
464        { return passField.get_text(); }
465    DOMString getNick()
466        { return nickField.get_text(); }
468 private:
470     void okCallback();
471     void cancelCallback();
473     bool doSetup();
475     Gtk::Table table;
477     Gtk::Label groupLabel;
478     Gtk::Entry groupField;
479     Gtk::Label hostLabel;
480     Gtk::Entry hostField;
481     Gtk::Label passLabel;
482     Gtk::Entry passField;
483     Gtk::Label nickLabel;
484     Gtk::Entry nickField;
486     PedroGui &parent;
487 };
490 //#########################################################################
491 //# F I L E    S E N D    D I A L O G
492 //#########################################################################
494 class FileSendDialog : public Gtk::Dialog
496 public:
498     FileSendDialog(PedroGui &par) : parent(par)
499         { doSetup(); }
501     virtual ~FileSendDialog()
502         {}
504    DOMString getFileName()
505        { return fileName; }
506    DOMString getJid()
507        { return jidField.get_text(); }
508   void setJid(const DOMString &val)
509        { return jidField.set_text(val); }
511 private:
513     void okCallback();
514     void cancelCallback();
515     void buttonCallback();
517     bool doSetup();
519     Gtk::Table table;
521     Gtk::Label jidLabel;
522     Gtk::Entry jidField;
524     DOMString fileName;
525     Gtk::Entry fileNameField;
527     Gtk::Button selectFileButton;
529     PedroGui &parent;
530 };
532 //#########################################################################
533 //# F I L E    R E C E I V E    D I A L O G
534 //#########################################################################
536 class FileReceiveDialog : public Gtk::Dialog
538 public:
540     FileReceiveDialog(PedroGui &par,
541                       const DOMString &jidArg,
542                       const DOMString &iqIdArg,
543                       const DOMString &streamIdArg,
544                       const DOMString &offeredNameArg,
545                       const DOMString &descArg,
546                       long  sizeArg,
547                       const DOMString &hashArg
548                       ) : parent(par)
549         {
550         jid         = jidArg;
551         iqId        = iqIdArg;
552         streamId    = streamIdArg;
553         offeredName = offeredNameArg;
554         desc        = descArg;
555         fileSize    = sizeArg;
556         hash        = hashArg;
557         doSetup();
558         }
560     virtual ~FileReceiveDialog()
561         {}
563    DOMString getJid()
564        { return jid; }
565    DOMString getIq()
566        { return iqId; }
567    DOMString getStreamId()
568        { return streamId; }
569    DOMString getOfferedName()
570        { return offeredName; }
571    DOMString getFileName()
572        { return fileName; }
573    DOMString getDescription()
574        { return desc; }
575    long getSize()
576        { return fileSize; }
577    DOMString getHash()
578        { return hash; }
580 private:
582     void okCallback();
583     void cancelCallback();
584     void buttonCallback();
586     bool doSetup();
588     Gtk::Table table;
590     Gtk::Label jidLabel;
591     Gtk::Entry jidField;
592     Gtk::Label offeredLabel;
593     Gtk::Entry offeredField;
594     Gtk::Label descLabel;
595     Gtk::Entry descField;
596     Gtk::Label sizeLabel;
597     Gtk::Entry sizeField;
598     Gtk::Label hashLabel;
599     Gtk::Entry hashField;
601     Gtk::Entry fileNameField;
603     Gtk::Button selectFileButton;
605     DOMString jid;
606     DOMString iqId;
607     DOMString streamId;
608     DOMString offeredName;
609     DOMString desc;
610     long      fileSize;
611     DOMString hash;
613     DOMString fileName;
615     PedroGui &parent;
616 };
620 //#########################################################################
621 //# M A I N    W I N D O W
622 //#########################################################################
624 class PedroGui : public Gtk::Window
626 public:
628     PedroGui();
630     virtual ~PedroGui();
632     virtual void error(const char *fmt, ...);
634     virtual void status(const char *fmt, ...);
636     //Let everyone share this
637     XmppClient client;
640     /**
641      *
642      */
643     virtual void doEvent(const XmppEvent &event);
645     /**
646      *
647      */
648     bool PedroGui::checkEventQueue();
651     bool chatCreate(const DOMString &userJid);
652     bool chatDelete(const DOMString &userJid);
653     bool chatDeleteAll();
654     bool chatMessage(const DOMString &jid, const DOMString &data);
656     bool groupChatCreate(const DOMString &groupJid,
657                          const DOMString &nick);
658     bool groupChatDelete(const DOMString &groupJid,
659                          const DOMString &nick);
660     bool groupChatDeleteAll();
661     bool groupChatMessage(const DOMString &groupJid,
662               const DOMString &from, const DOMString &data);
663     bool groupChatPresence(const DOMString &groupJid,
664                            const DOMString &nick,
665                            bool presence,
666                            const DOMString &show,
667                            const DOMString &status);
669     void doChat(const DOMString &jid);
670     void doSendFile(const DOMString &jid);
671     void doReceiveFile(const DOMString &jid,
672                        const DOMString &iqId,
673                        const DOMString &streamId,
674                        const DOMString &offeredName,
675                        const DOMString &desc,
676                        long  size,
677                        const DOMString &hash);
679 private:
682     //# File menu
683     void connectCallback();
684     void chatCallback();
685     void groupChatCallback();
686     void disconnectCallback();
687     void quitCallback();
689     //# Edit menu
690     void fontCallback();
691     void colorCallback();
693     //# Transfer menu
694     void sendFileCallback();
696     //# Help menu
697     void aboutCallback();
699     bool doSetup();
701     Gtk::VBox mainBox;
703     Pango::FontDescription fontDesc;
704     Gdk::Color foregroundColor;
705     Gdk::Color backgroundColor;
707     Gtk::VPaned vPaned;
708     MessageList messageList;
709     Roster      roster;
711     Glib::RefPtr<Gtk::UIManager> uiManager;
712     void actionEnable(const DOMString &name, bool val);
714     std::vector<ChatWindow *>chats;
716     std::vector<GroupChatWindow *>groupChats;
718     static const int writeBufLen = 2048;
720     char writeBuf[writeBufLen];
721 };
724 } //namespace Pedro
726 #endif /* __PEDROGUI_H__ */
727 //#########################################################################
728 //# E N D    O F    F I L E
729 //#########################################################################