LeechCraft  0.6.70-6645-gcd10d7e
Modular cross-platform feature rich live environment.
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 <util/sll/util.h>
38 #include "svcauthconfig.h"
39 
40 class QTimer;
41 
42 template<typename>
43 class QFuture;
44 
45 namespace LeechCraft
46 {
47 namespace Util
48 {
49 class QueueManager;
50 enum class QueuePriority;
51 
52 class CustomCookieJar;
53 
54 namespace SvcAuth
55 {
56  class UTIL_SVCAUTH_API VkAuthManager : public QObject
57  {
58  Q_OBJECT
59 
60  ICoreProxy_ptr Proxy_;
61 
62  const QString AccountHR_;
63 
64  QNetworkAccessManager * const AuthNAM_;
65  Util::CustomCookieJar * const Cookies_;
66 
67  QueueManager * const Queue_;
68 
69  QString Token_;
70  QDateTime ReceivedAt_;
71  qint32 ValidFor_;
72 
73  bool IsRequesting_;
74 
75  const QString ID_;
76  QUrl URL_;
77 
78  bool IsRequestScheduled_;
79  QTimer * const ScheduleTimer_;
80 
81  bool SilentMode_ = false;
82 
83  bool HasTracked_ = false;
84  public:
87 
90 
92  private:
93  QList<RequestQueue_ptr> ManagedQueues_;
94  QList<PrioRequestQueue_ptr> PrioManagedQueues_;
95  public:
96  VkAuthManager (const QString& accountName, const QString& clientId,
97  const QStringList& scope, const QByteArray& cookies,
98  ICoreProxy_ptr, QueueManager* = nullptr, QObject* = nullptr);
99 
100  bool IsAuthenticated () const;
101  bool HadAuthentication () const;
102 
103  void UpdateScope (const QStringList&);
104 
105  void GetAuthKey ();
106 
107  QFuture<QString> GetAuthKeyFuture ();
108 
109  ScheduleGuard_t Q_REQUIRED_RESULT ManageQueue (RequestQueue_ptr);
110  ScheduleGuard_t Q_REQUIRED_RESULT ManageQueue (PrioRequestQueue_ptr);
111 
112  void SetSilentMode (bool);
113  private:
114  void InvokeQueues (const QString&);
115 
116  void RequestURL (const QUrl&);
117  void RequestAuthKey ();
118  bool CheckReply (QUrl);
119  bool CheckError (const QUrl&);
120 
121  void ScheduleTrack (const QString&);
122  public slots:
123  void clearAuthData ();
124  void reauth ();
125  private slots:
126  void execScheduledRequest ();
127  void handleGotForm ();
128  void handleViewUrlChanged (const QUrl&);
129  signals:
130  void gotAuthKey (const QString&);
131  void cookiesChanged (const QByteArray&);
132  void authCanceled ();
133  void justAuthenticated ();
134  };
135 }
136 }
137 }
detail::ScopeGuard< detail::DefaultScopeGuardDeleter > DefaultScopeGuard
Definition: util.h:104
#define UTIL_SVCAUTH_API
Definition: svcauthconfig.h:37
std::shared_ptr< ICoreProxy > ICoreProxy_ptr
Definition: icoreproxy.h:225
QueuePriority
The priority of the action in the queue.
Definition: queuemanager.h:48
A simple scheduling manager for a queue of functors.
Definition: queuemanager.h:64