LeechCraft  %{LEECHCRAFT_VERSION}
Modular cross-platform feature rich live environment.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
vkauthmanager.h
Go to the documentation of this file.
1 /**********************************************************************
2  * LeechCraft - modular cross-platform feature rich internet client.
3  * Copyright (C) 2006-2014 Georg Rudoy
4  *
5  * Boost Software License - Version 1.0 - August 17th, 2003
6  *
7  * Permission is hereby granted, free of charge, to any person or organization
8  * obtaining a copy of the software and accompanying documentation covered by
9  * this license (the "Software") to use, reproduce, display, distribute,
10  * execute, and transmit the Software, and to prepare derivative works of the
11  * Software, and to permit third-parties to whom the Software is furnished to
12  * do so, all subject to the following:
13  *
14  * The copyright notices in the Software and this entire statement, including
15  * the above license grant, this restriction and the following disclaimer,
16  * must be included in all copies of the Software, in whole or in part, and
17  * all derivative works of the Software, unless such copies or derivative
18  * works are solely in the form of machine-executable object code generated by
19  * a source language processor.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
24  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
25  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
26  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  **********************************************************************/
29 
30 #pragma once
31 
32 #include <functional>
33 #include <QObject>
34 #include <QDateTime>
35 #include <QUrl>
37 #include "svcauthconfig.h"
38 
39 class QTimer;
40 
41 namespace LeechCraft
42 {
43 namespace Util
44 {
45 class QueueManager;
46 enum class QueuePriority;
47 
48 class CustomCookieJar;
49 
50 namespace SvcAuth
51 {
52  class UTIL_SVCAUTH_API VkAuthManager : public QObject
53  {
54  Q_OBJECT
55 
56  ICoreProxy_ptr Proxy_;
57 
58  const QString AccountHR_;
59 
60  QNetworkAccessManager *AuthNAM_;
61  Util::CustomCookieJar *Cookies_;
62 
63  QueueManager * const Queue_;
64 
65  QString Token_;
66  QDateTime ReceivedAt_;
67  qint32 ValidFor_;
68 
69  bool IsRequesting_;
70 
71  const QString ID_;
72  QUrl URL_;
73 
74  bool IsRequestScheduled_;
75  QTimer *ScheduleTimer_;
76 
77  bool SilentMode_ = false;
78  public:
80  typedef RequestQueue_t* RequestQueue_ptr;
81 
83  typedef PrioRequestQueue_t* PrioRequestQueue_ptr;
84  private:
85  QList<RequestQueue_ptr> ManagedQueues_;
86  QList<PrioRequestQueue_ptr> PrioManagedQueues_;
87  public:
88  VkAuthManager (const QString& accountName, const QString& clientId,
89  const QStringList& scope, const QByteArray& cookies,
90  ICoreProxy_ptr, QueueManager* = nullptr, QObject* = nullptr);
91 
92  bool IsAuthenticated () const;
93  bool HadAuthentication () const;
94 
95  void UpdateScope (const QStringList&);
96 
97  void GetAuthKey ();
98 
99  void ManageQueue (RequestQueue_ptr);
100  void UnmanageQueue (RequestQueue_ptr);
101 
102  void ManageQueue (PrioRequestQueue_ptr);
103  void UnmanageQueue (PrioRequestQueue_ptr);
104 
105  void SetSilentMode (bool);
106  private:
107  void InvokeQueues (const QString&);
108 
109  void HandleError ();
110  void RequestURL (const QUrl&);
111  void RequestAuthKey ();
112  bool CheckIsBlank (QUrl);
113  public slots:
114  void clearAuthData ();
115  void reauth ();
116  private slots:
117  void execScheduledRequest ();
118  void handleGotForm ();
119  void handleViewUrlChanged (const QUrl&);
120  signals:
121  void gotAuthKey (const QString&);
122  void cookiesChanged (const QByteArray&);
123  void authCanceled ();
124  void justAuthenticated ();
125  };
126 }
127 }
128 }
std::shared_ptr< ICoreProxy > ICoreProxy_ptr
Definition: icoreproxy.h:225
#define UTIL_SVCAUTH_API
Definition: svcauthconfig.h:37
QList< QPair< std::function< void(QString)>, QueuePriority > > PrioRequestQueue_t
Definition: vkauthmanager.h:82
QList< std::function< void(QString)> > RequestQueue_t
Definition: vkauthmanager.h:79
A simple scheduling manager for a queue of functors.
Definition: queuemanager.h:57