2 Copyright 2013-2015 Mats Sjöberg
4 This file is part of the Pumpa programme.
6 Pumpa is free software: you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 Pumpa is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Pumpa. If not, see <http://www.gnu.org/licenses/>.
25 #include <QDesktopServices>
26 #include <QApplication>
27 #include <QMainWindow>
31 #include <QMessageBox>
32 #include <QSystemTrayIcon>
33 #include <QProgressDialog>
38 #include <QDBusInterface>
43 #include "pumpa_defines.h"
44 #include "qactivitystreams.h"
45 #include "collectionwidget.h"
46 #include "oauthwizard.h"
47 #include "tabwidget.h"
48 #include "pumpasettingsdialog.h"
49 #include "pumpasettings.h"
50 #include "contextwidget.h"
51 #include "objectlistwidget.h"
52 #include "messagewindow.h"
53 #include "filedownloader.h"
54 #include "editprofiledialog.h"
56 //------------------------------------------------------------------------------
58 class PumpApp
: public QMainWindow
{
62 PumpApp(PumpaSettings
* settings
, QString locale
="", QWidget
* parent
=0);
66 void userAuthorizationStarted();
69 void onSslErrors(QNetworkReply
*, QList
<QSslError
>);
71 void userTestDoneAndFollow();
73 void trayIconActivated(QSystemTrayIcon::ActivationReason reason
);
74 void updateTrayIcon();
76 void timelineHighlighted(int);
77 void onNewMinorObjects();
81 void editProfileDialog();
82 void onLike(QASObject
* obj
);
83 void onShare(QASObject
* obj
);
84 void postNote(QString note
, QString title
,
85 RecipientList to
, RecipientList cc
);
86 void postImage(QString msg
, QString title
, QString imageFile
,
87 RecipientList to
, RecipientList cc
);
88 void postAvatarImage(QString imageFile
);
89 void postReply(QASObject
* replyToObj
, QString content
,
90 RecipientList to
, RecipientList cc
);
91 void postEdit(QASObject
* obj
, QString content
, QString title
);
92 void follow(QString acctId
, bool follow
);
93 void onDeleteObject(QASObject
* obj
);
94 void onEditObject(QASObject
* obj
);
95 void onProfileEdited(QASActor
* profile
, QString newImageFile
);
97 void errorMessage(QString msg
);
98 void notifyMessage(QString msg
);
99 void statusMessage(const QString
& msg
);
100 void onShowContext(QASObject
*);
101 void tabSelected(int index
);
103 void onClientRegistered(QString
, QString
, QString
, QString
);
104 void onAccessTokenReceived(QString token
, QString tokenSecret
);
106 void onAuthorizedRequestReady(QByteArray response
, int id
);
108 void uploadProgress(qint64 bytesSent
, qint64 bytesTotal
);
109 void uploadCanceled(bool abortRequest
=true);
111 void request(QString endpoint
, int response_id
,
112 KQOAuthRequest::RequestHttpMethod method
= KQOAuthRequest::GET
,
113 QVariantMap data
=QVariantMap());
119 void newNote(QASObject
* obj
= NULL
, QASObjectList
* to
= NULL
,
120 QASObjectList
* cc
= NULL
, bool edit
= false);
126 void launchOAuthWizard();
127 void wizardCancelled();
131 void showFollowers();
132 void showFollowing();
133 void showFavourites();
134 void showUserActivities();
139 void timerEvent(QTimerEvent
*);
140 virtual bool event(QEvent
* e
) {
141 if (e
->type() == QEvent::WindowActivate
)
142 resetNotifications();
143 return QMainWindow::event(e
);
145 void closeEvent(QCloseEvent
* e
) {
146 m_showHideAction
->setText(showHideText(false));
147 QMainWindow::closeEvent(e
);
151 void addPublicRecipient(RecipientList
& rl
);
153 void uploadProfile();
155 bool tabShown(ASWidget
* aw
) const;
157 bool isShown(QASAbstractObject
* obj
);
159 KQOAuthRequest
* initRequest(QString endpoint
,
160 KQOAuthRequest::RequestHttpMethod method
);
161 QNetworkReply
* executeRequest(KQOAuthRequest
* request
, int response_id
);
163 typedef QPair
<KQOAuthRequest
*, int> requestInfo_t
;
164 QMap
<int, requestInfo_t
> m_requestMap
;
167 void setLoading(bool on
);
168 void refreshObject(QASAbstractObject
* obj
);
170 void uploadFile(QString filename
, int flags
=0);
172 void updatePostedImage(QVariantMap obj
, int flags
=0);
173 void postImageActivity(QVariantMap obj
, int flags
=0);
175 void errorBox(QString msg
);
177 bool webFingerFromString(QString text
, QString
& username
, QString
& server
);
179 void testUserAndFollow(QString username
, QString server
);
181 QString
apiUrl(QString endpoint
);
183 // constructs api/user/$username/$path
184 QString
apiUser(QString path
);
186 void addRecipient(QVariantMap
& data
, QString name
, RecipientList to
);
188 void resetNotifications();
190 void createTrayIcon();
191 QString
showHideText(bool);
192 QString
showHideText() { return showHideText(isVisible()); }
194 void connectCollection(ASWidget
* w
, bool highlight
=true);
200 void refreshTimeLabels();
203 QString
inboxEndpoint(QString path
);
205 void feed(QString verb
, QVariantMap object
, int response_id
,
206 RecipientList to
= RecipientList(),
207 RecipientList cc
= RecipientList());
209 bool sendNotification(QString summary
, QString text
);
211 PumpaSettingsDialog
* m_settingsDialog
;
214 void followActor(QASActor
* actor
, bool doFollow
=true);
215 void addCompletion(QString from
, QString to
, bool add
);
217 void createActions();
220 QAction
* newNoteAction
;
221 // QAction* newPictureAction;
222 QAction
* reloadAction
;
223 QAction
* followAction
;
224 QAction
* profileAction
;
225 QAction
* loadOlderAction
;
226 QAction
* openPrefsAction
;
230 QAction
* aboutAction
;
231 QAction
* aboutQtAction
;
232 QAction
* reportBugAction
;
235 QAction
* m_followersAction
;
236 QAction
* m_followingAction
;
237 QAction
* m_favouritesAction
;
238 QAction
* m_userActivitiesAction
;
239 QAction
* m_firehoseAction
;
240 QAction
* m_closeTabAction
;
243 QAction
* m_debugAction
;
245 KQOAuthManager
*m_oam
;
247 FileDownloadManager
* m_fdm
;
249 TabWidget
* m_tabWidget
;
250 CollectionWidget
* m_inboxWidget
;
251 CollectionWidget
* m_directMajorWidget
;
252 CollectionWidget
* m_directMinorWidget
;
253 CollectionWidget
* m_inboxMinorWidget
;
254 CollectionWidget
* m_firehoseWidget
;
255 QList
<ContextWidget
*> m_contextWidgets
;
256 ObjectListWidget
* m_followersWidget
;
257 ObjectListWidget
* m_followingWidget
;
258 ObjectListWidget
* m_favouritesWidget
;
259 CollectionWidget
* m_userActivitiesWidget
;
265 QASActor
* m_selfActor
;
269 MessageWindow
* m_messageWindow
;
271 EditProfileDialog
* m_editProfileDialog
;
273 QSystemTrayIcon
* m_trayIcon
;
274 QMenu
* m_trayIconMenu
;
275 QAction
* m_showHideAction
;
282 QVariantMap m_imageObject
;
283 RecipientList m_imageTo
;
284 RecipientList m_imageCc
;
285 QVariantMap m_profile
;
287 RecipientList m_recipientLists
;
289 MessageEdit::completion_t m_completions
;
291 QProgressDialog
* m_uploadDialog
;
292 QNetworkReply
* m_uploadRequest
;
294 QNetworkAccessManager
* m_nam
;
296 QSignalMapper
* m_notifyMap
;
298 QDBusInterface
* m_dbus
;
302 #endif /* _PUMPAPP_H_ */