session.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright 2009 Andrew Stromme <astromme@chatonka.com>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU Library General Public License as
  6. * published by the Free Software Foundation; either version 2, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details
  13. *
  14. * You should have received a copy of the GNU Library General Public
  15. * License along with this program; if not, write to the
  16. * Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. */
  19. #ifndef RTM_SESSION_H
  20. #define RTM_SESSION_H
  21. #include <QObject>
  22. #include <QDateTime>
  23. #include "rtm.h"
  24. #include "task.h"
  25. namespace RTM {
  26. class Request;
  27. class SessionPrivate;
  28. class TasksReader;
  29. }
  30. /** @file
  31. * This file is part of librtm. It defines
  32. * the RTM::Session which is the main high-level
  33. * interface to a Remember The Milk session
  34. *
  35. * @author Andrew Stromme <astromme@chatonka.com>
  36. */
  37. /**
  38. * Provides a set of classes for interacting with the Remember The Milk online todo management service
  39. */
  40. namespace RTM {
  41. /**
  42. * @brief The Session class provides a high level interface to a Remember The Milk session
  43. *
  44. * @author Andrew Stromme <astromme@chatonka.com>
  45. */
  46. class RTM_EXPORT Session : public QObject
  47. {
  48. Q_OBJECT
  49. public:
  50. Session(QString apiKey, QString sharedSecret, RTM::Permissions permissions, QString token = QString(), QObject *parent = 0);
  51. virtual ~Session();
  52. QString getAuthUrl() const;
  53. void showLoginWindow();
  54. bool authenticated() const;
  55. RTM::Request* request(const QString& method);
  56. void connectTaskRequest(RTM::Request *request);
  57. void connectListRequest(RTM::Request *request);
  58. void setTimeline(const RTM::Timeline& timeline);
  59. RTM::Timeline getTimeline() const;
  60. void createTimeline();
  61. void checkToken();
  62. QString apiKey() const;
  63. QString sharedSecret() const;
  64. QString token() const;
  65. RTM::Permissions permissions() const;
  66. void refreshTasksFromServer();
  67. void refreshListsFromServer();
  68. QHash<RTM::TaskId,RTM::Task*> cachedTasks() const;
  69. QHash<RTM::ListId,RTM::List*> cachedLists() const;
  70. RTM::Task* taskFromId(RTM::TaskId id) const;
  71. RTM::Task* newBlankTask(RTM::TaskId id) const;
  72. RTM::List* listFromId(RTM::ListId id) const;
  73. RTM::List* newBlankList(RTM::ListId id) const;
  74. public Q_SLOTS:
  75. void setToken(const QString &token);
  76. void handleResponse();
  77. void continueAuthForToken();
  78. void addTask(const QString &task, RTM::ListId listId);
  79. RTM::Task* createTaskFromString(const QString& task);
  80. void tokenCheckReply(RTM::Request*);
  81. void handleValidToken(bool);
  82. void timelineReply(RTM::Request*);
  83. Q_SIGNALS:
  84. void tokenReceived(const QString& token);
  85. void tokenCheck(bool success);
  86. void timelineCreated(RTM::Timeline timeline);
  87. void taskChanged(RTM::Task* task);
  88. void listChanged(RTM::List* list);
  89. void tasksChanged();
  90. void listsChanged();
  91. private:
  92. friend class TasksReader;
  93. friend class SessionPrivate;
  94. SessionPrivate * const d;
  95. Q_PRIVATE_SLOT(d, void taskUpdate(RTM::Request* reply))
  96. Q_PRIVATE_SLOT(d, void listUpdate(RTM::Request* reply))
  97. Q_PRIVATE_SLOT(d, void smartListReply(RTM::Request* reply))
  98. };
  99. } // Namespace RTM
  100. #endif