OSDN Git Service

b8c889ee1a15d9c332ab9789f6899e8a70976b55
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / oauth / NNOAuthNetworkAccessManager.java
1
2 /*
3  * This file is part of NixNote 
4  * Copyright 2012 Randy Baumgarte
5  * 
6  * This file may be licensed under the terms of of the
7  * GNU General Public License Version 2 (the ``GPL'').
8  *
9  * Software distributed under the License is distributed
10  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
11  * express or implied. See the GPL for the specific language
12  * governing rights and limitations.
13  *
14  * You should have received a copy of the GPL along with this
15  * program. If not, go to http://www.gnu.org/licenses/gpl.html
16  * or write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  */
20
21 /* This class is used to listen to inbound network requests.  It 
22  * examines all of them to look for the OAuth reply.  This reply
23  * is what we need to get access to Evernote.
24  */
25
26 package cx.fbn.nevernote.oauth;
27
28 import com.trolltech.qt.core.QIODevice;
29 import com.trolltech.qt.core.QObject;
30 import com.trolltech.qt.network.QNetworkAccessManager;
31 import com.trolltech.qt.network.QNetworkReply;
32 import com.trolltech.qt.network.QNetworkRequest;
33
34 import cx.fbn.nevernote.utilities.ApplicationLogger;
35
36 public class NNOAuthNetworkAccessManager extends QNetworkAccessManager {
37         public Signal1<String> tokenFound;
38         private ApplicationLogger logger;
39
40         public NNOAuthNetworkAccessManager(ApplicationLogger l){
41                 super();
42                 tokenFound = new Signal1<String>();
43                 logger = l;
44         }
45
46         public NNOAuthNetworkAccessManager(QObject qObject){
47                 super(qObject);
48                 tokenFound = new Signal1<String>();
49         }
50
51         @Override
52         protected QNetworkReply createRequest(Operation op,
53                         QNetworkRequest request, QIODevice outgoingData) {
54
55                 logger.log(logger.EXTREME,"NNOAuthNetworkAccessManager URL request scheme: " 
56                                 +request.url().scheme() + " " + request.url().toString());
57                 String searchReq = "nnoauth?oauth_token=";
58                 int pos = request.url().toString().indexOf(searchReq);
59                 if (pos>0) {
60                         String token = request.url().toString().substring(pos+searchReq.length());
61                         tokenFound.emit(token);
62                 }
63                 return super.createRequest(op, request, outgoingData);
64         }               
65 }