1 /*
2  * This file is part of Licq, an instant messaging client for UNIX.
3  * Copyright (C) 2000-2014 Licq developers <licq-dev@googlegroups.com>
4  *
5  * Licq 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  * Licq 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.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with Licq; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  */
19 
20 #ifndef LICQGUI_USERSENDEVENT_H
21 #define LICQGUI_USERSENDEVENT_H
22 
23 #include "usereventcommon.h"
24 
25 #include <list>
26 #include <string>
27 
28 #include <licq/color.h>
29 
30 class QGroupBox;
31 class QLabel;
32 class QPushButton;
33 class QSplitter;
34 
35 namespace Licq
36 {
37 class Event;
38 }
39 
40 namespace LicqQtGui
41 {
42 class HistoryView;
43 class MLEdit;
44 class MMUserView;
45 
46 class UserSendEvent : public UserEventCommon
47 {
48   Q_OBJECT
49 public:
50   /**
51    * Constructor, create and open send event dialog
52    *
53    * @param type Type of event
54    * @param userId User to open dialog for
55    * @param parent Parent widget
56    */
57   UserSendEvent(int type, const Licq::UserId& userId, QWidget* parent = 0);
58   virtual ~UserSendEvent();
59   virtual bool eventFilter(QObject* watched, QEvent* e);
60 
61   void setText(const QString& text);
62   void setUrl(const QString& url, const QString& description);
63   void setContact(const Licq::UserId& userId);
64   void setFile(const QString& file, const QString& description);
65   void addFile(const QString& file);
66 
67   /**
68    * Someone joined the conversation
69    *
70    * @param userId User that joined conversation
71    */
72   void convoJoin(const Licq::UserId& userId);
73 
74   /**
75    * Someone left the conversation
76    *
77    * @param userId User that left conversation
78    */
79   void convoLeave(const Licq::UserId& userId);
80 
81   virtual void changeEvent(QEvent* event);
82   int clearDelay;
83 
84 signals:
85   void autoCloseNotify();
86 
87   /**
88    * Since daemon doesn't notify us when an event is sent we'll have to handle
89    * it ourselfs. This signal is sent to notify other windows about the event
90    * that was sent.
91    *
92    * @param event Event object that was sent
93    */
94   void eventSent(const Licq::Event* event);
95 
96 public slots:
97   /**
98    * Convert dialog to a specified event type
99    *
100    * @param type Type of event to switch to
101    */
102   void changeEventType(int type);
103 
104 protected:
105   Licq::Color myIcqColor;
106   HistoryView* myHistoryView;
107   MLEdit* myMessageEdit;
108   QAction* mySendServerCheck;
109   QAction* myUrgentCheck;
110   QAction* myEventTypeMenu;
111   QActionGroup* myEventTypeGroup;
112   QLabel* myPictureLabel;
113   QPushButton* myCloseButton;
114   QPushButton* mySendButton;
115   QSplitter* myViewSplitter;
116   QSplitter* myPictureSplitter;
117   QString myTempMessage;
118   QTimer* mySendTypingTimer;
119   int myType;
120   std::list<unsigned long> myEventTag;
121 
122   void retrySend(const Licq::Event* e, unsigned flags);
123 
124   /**
125    * A user has been update, this virtual function allows subclasses to add additional handling
126    * This function will only be called if user is in this conversation
127    *
128    * @param userId Updated user
129    * @param subSignal Type of update
130    * @param argument Signal specific argument
131    * @param cid Conversation id
132    */
133   virtual void userUpdated(const Licq::UserId& userId, unsigned long subSignal, int argument, unsigned long cid);
134   void updatePicture(const Licq::User* u = NULL);
135 
136   /**
137    * Get icon for a message type
138    *
139    * @param type Message type
140    * @return Message icon
141    */
142   const QPixmap& iconForType(int type) const;
143 
144   /**
145    * Widget is about to be closed
146    * Overloaded to make sure widget is always removed from tab dialog before it's destroyed
147    *
148    * @parame event Close event
149    */
150   virtual void closeEvent(QCloseEvent* event);
151 
152   /**
153    * Overloaded resize event to save new dialog size
154    *
155    * @param event Resize event
156    */
157   virtual void resizeEvent(QResizeEvent* event);
158 
159 protected slots:
160   /**
161    * Update iconset in menus and on buttons
162    */
163   virtual void updateIcons();
164 
165   /// Update toolbar button for emoticons
166   void updateEmoticons();
167 
168   /**
169    * Update keyboard shortcuts
170    */
171   virtual void updateShortcuts();
172 
173 private slots:
174   /// Send button was pressed
175   void send();
176 
177   void eventDoneReceived(const Licq::Event* e);
178 
179   void cancelSend();
180   void changeEventType(QAction* action);
181   void clearNewEvents();
182   void closeDialog();
183   void showEmoticonsMenu();
184   void insertEmoticon(const QString& value);
185   void messageAdded();
186   void resetTitle();
187   void sendServerToggled(bool on);
188   void setBackgroundICQColor();
189   void setForegroundICQColor();
190   void showSendTypeMenu();
191   void messageTextChanged();
192   void textChangedTimeout();
193   void sendTrySecure();
194 
195   /**
196    * A dragged object has entered this widget
197    * Overloaded to accept files, URLs and users to be sent by dragging them
198    *
199    * @param event The drag event
200    */
201   void dragEnterEvent(QDragEnterEvent* event);
202 
203   /**
204    * A dragged object was dropped on this widget
205    * Overloaded to accept files, URLs and users to be sent by dragging them
206    *
207    * @param event The drop event
208    */
209   void dropEvent(QDropEvent* event);
210 
211   /// Select chat to invite user to
212   void chatInviteUser();
213 
214   /// File browse button was pressed
215   void fileBrowse();
216 
217   /// File edit button was pressed
218   void fileEditList();
219 
220   /// Update label for file transfer
221   void fileUpdateLabel(unsigned count);
222 
223 private:
224   /// Show/hide controls for current event type
225   void setEventType();
226 
227   /// Common base part of send function
228   void sendBase();
229 
230 
231   QString myTitle;
232 
233   QWidget* myUrlControls;
234   InfoField* myUrlEdit;
235 
236   QWidget* myContactsControls;
237   MMUserView* myContactsList;
238 
239   QWidget* myChatControls;
240   InfoField* myChatItemEdit;
241   QPushButton* myChatInviteButton;
242   unsigned short myChatPort;
243   QString myChatClients;
244 
245   QWidget* myFileControls;
246   InfoField* myFileEdit;
247   QPushButton* myFileBrowseButton;
248   QPushButton* myFileEditButton;
249   std::list<std::string> myFileList;
250 };
251 
252 } // namespace LicqQtGui
253 #endif
254