OSDN Git Service

Merge remote-tracking branch 'origin/master'
[memma/Source.git] / widget.h
1 /**
2  * CommandoJikkyouSennyou - Commando Jikkyou Sennyou Client for twitter for Qt.
3  *
4  * Author: amayav (vamayav@yahoo.co.jp)
5  *
6  *
7  *  CommandoJikkyouSennyou is free software: you can redistribute it and/or modify
8  *  it under the terms of the GNU Lesser General Public License as published by
9  *  the Free Software Foundation, either version 3 of the License, or
10  *  (at your option) any later version.
11  *
12  *  CommandoJikkyouSennyou is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU Lesser General Public License for more details.
16  *
17  *  You should have received a copy of the GNU Lesser General Public License
18  *  along with CommandoJikkyouSennyou.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 /******************************************************************************
21
22   widget.h
23
24 ******************************************************************************/
25
26 #ifndef WIDGET_H
27
28 #define WIDGET_H
29
30 #include <QSettings>
31 #include <QWidget>
32 #include <QtKOAuth>
33 #include <QNetworkReply>
34 #include <QShortcut>
35 #include "widgetdomain.h"
36 #include <QNetworkProxy>
37 #include <QTimer>
38 #include "latesttweetsfortime.h"
39
40 class KQOAuthManager;
41 class KQOAuthRequest;
42 //class KQOAuthRequest_XAuth;
43
44
45 namespace Ui {
46 class Widget;
47 }
48
49 class Widget : public QWidget {
50     Q_OBJECT
51
52 public:
53     explicit Widget(QWidget *parent = 0);
54     ~Widget();
55
56 protected:
57     void keyPressEvent(QKeyEvent *);
58     void keyReleaseEvent(QKeyEvent *);
59     void resizeEvent(QResizeEvent *);
60     void showEvent(QShowEvent *);
61
62 private slots:
63     void onTemporaryTokenReceived(QString token, QString tokenSecret);
64     void onAuthorizationReceived(QString token, QString verifier);
65     void onAccessTokenReceived(QString token, QString tokenSecret);
66     void onAuthorizedRequestDone();
67     void onRequestReady(QByteArray response);
68     void onRequestReadyTimeline(QByteArray response);
69     void onRequestReadyOwnPosts(QByteArray);
70     void onReadyRead();
71     void sendTweet(QString tweet);
72     void receiveSSLError(QNetworkReply * reply, const QList<QSslError> & errors);
73     void readOwnPosts(QNetworkReply * r);
74
75     void countDownClock();
76
77     void updateData();
78
79     /**
80       Open authorizing web page in twitter.com.
81       */
82     void on_authorizationButton_clicked();
83
84     /**
85       Start Timeline flowing.
86       */
87     void on_showTimeLineButton_clicked();
88
89     /**
90       Set authorizing this program with twitter.com.
91       */
92     void on_verificationButton_clicked();
93
94     /**
95       Post some text to twitter.com.
96       */
97     void on_postButton_clicked();
98
99     void on_lineEdit_2_textChanged(const QString &arg1);
100     void on_lineEdit_3_textChanged(const QString &arg1);
101     void on_lineEdit_4_textChanged(const QString &arg1);
102     void on_lineEdit_5_textChanged(const QString &arg1);
103     void on_lineEdit_6_textChanged(const QString &arg1);
104
105     void on_proxyButton_clicked();
106
107 private:
108     Ui::Widget *ui;
109
110     KQOAuthManager *_oauthManager;
111     KQOAuthRequest *_oauthRequest;
112     //  KQOAuthRequest_XAuth *oauthRequestX;
113     QSettings *_oauthSettings, *_shortCutKeysSettings, *_sizeSettings;
114     QNetworkProxy *_proxy;
115     QString _consumerKey;
116     QString _consumerSecretKey;
117     QTimer *_clockCountTimer;
118     LatestTweetsForTime _latestTweetsForTime;
119
120     WidgetDomain *_subject;
121
122     bool setPostShortcutKeys();
123     bool setJikkyouShortcutKeys();
124     bool setWindowSize();
125     bool setProxyLineEdits();
126     bool setConsumerKeyAndConsumerSecretLineEdits();
127     bool setConsumerKeyAndConsumerSecret();
128     bool initializeKQOAuth();
129
130     bool setConsumerKeyAndConsumerSecretSettings();
131
132     void showFatalError(const QString strMsg, const int nNum = 0,
133                         const QString strTitle = tr("Fatal Error!"));
134     void showOAuthError(const int nErrNum);
135
136     /**
137       Initialize widget which has user own post data.
138       Latest 130 and Latest 10.
139       */
140     bool initializeOwnPostsWidgets();
141
142     /**
143       Replace text from PlaneTextEdit to twitter.
144       */
145     bool replacePlainTextEditContent(int i, QString str);
146
147     /**
148       Set shortcut key config.
149       */
150     bool setShortCutKeyAndContext(QShortcut *sc, QKeySequence s, Qt::ShortcutContext c);
151
152     /**
153       Connect with twitter.com by SSL.
154       This is copied and changed from KQOauthManager::executeRequest(KQOAuthRequest *request)
155       */
156     bool SSLconnect(KQOAuthRequest *request);
157
158     /**
159       set consumerKey and consumerSecretKey to oauthRequest.
160       */
161     bool initializeRequest(QUrl url,
162                            KQOAuthRequest::RequestHttpMethod requestMethod = KQOAuthRequest::POST,
163                            KQOAuthRequest::RequestType requestType = KQOAuthRequest::AuthorizedRequest);
164
165     bool setTokenAndSecretTokenToRequest();
166
167     bool SetButtonsEnable(bool on = true);
168     QByteArray makeAuthHeaderFrom(QList<QByteArray> requestParameters);
169     bool isOAuthed();
170     QString getValueOfMatchedKey();
171     WidgetDomain* getWidgetDomain();
172
173 signals:
174     void verificationReceived1(QString oauth_verifier);
175 };
176
177 #endif // WIDGET_H