forked from eduardoc7/qtcreator-plugin-discord-presence
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcutediscordpresence.h
109 lines (82 loc) · 3.35 KB
/
cutediscordpresence.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#ifndef CUTEDISCORDPRESENCEPLUGIN_H
#define CUTEDISCORDPRESENCEPLUGIN_H
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/icontext.h>
#include <coreplugin/icore.h>
#include <extensionsystem/iplugin.h>
#include <projectexplorer/projecttree.h>
#include <projectexplorer/project.h>
#include <QTimer>
#include <QtWidgets/QMessageBox>
#include <QtWidgets/QMenu>
#include <QtGui/QAction>
#include <functional>
#include <iostream>
#include <string>
#include <discord_rpc.h>
namespace QtCreatorDRPC {
constexpr const char* GLOBAL_DRPC_CONTROL_MENU_ID { "QtCreatorDRPC.Menu" };
constexpr const char* GLOBAL_DRPC_CONTROL_MENU_START_ACTION_ID { "QtCreatorDRPC.Action.Start" };
constexpr const char* GLOBAL_DRPC_CONTROL_MENU_STOP_ACTION_ID { "QtCreatorDRPC.Action.Stop" };
constexpr const char* GLOBAL_DISCORD_APPLICATION_ID { "937400240473006092" };
class QDiscordRichPresence {
public:
QString State;
QString Details;
quint64 StartTimestamp;
quint64 EndTimestamp;
QString LargeImageKey;
QString LargeImageText;
QString SmallImageKey;
QString SmallImageText;
QString PartyId;
qint32 PartySize;
qint32 PartyMax;
QString MatchSecret;
QString SpectateSecret;
QString JoinSecret;
int8_t Instance;
void UpdateRichPresence() const;
QDiscordRichPresence();
};
class Q_DECL_EXPORT QtCreatorDRPCPlugin : public ExtensionSystem::IPlugin {
Q_OBJECT
Q_PLUGIN_METADATA( IID "org.qt-project.Qt.QtCreatorPlugin" FILE "CuteDiscordPresence.json" )
protected:
struct RichPresenceFileDescriptor {
QString ImageKey; // The key of the art asset stored in the rich presence developer portal used for this file.
QString Description; // Description of the file type, e.g. C++ Source File, Python Script, QMake Project File, etc...
QString WorkingVerb; // Verb used when referring to this file, e.g. editing, designing, configuring.
};
// Maps the mime types of files as QStrings, to their respective RichPresenceFileDescriptor.
static const QMap<QString, RichPresenceFileDescriptor> mimeTypeToRpcFileDescriptorMap;
class MimeOverrider {
public:
static QMap<QString, QList<QPair<QList<QString>, QString> > > MimeOverrideMap;
static QString OverrideMimeIfApplicable( const QString& mime, const Utils::FilePath& file_path );
};
std::time_t drpcActivatedTimestamp;
void initializeDiscordRichPresence( const char* application_id );
std::time_t timeSpentOnCurrentEditor;
QTimer drpcSyncTimer;
QList<QMetaObject::Connection> syncSignalConnections;
protected slots:
void setDrpcNotEditingState();
void syncDrpcToCurrentEditorState();
void activateDiscordRichPresence();
void deactivateDiscordRichPresence();
void initializeControlMenu();
public:
virtual bool initialize( const QStringList& arguments, QString* error_string ) override;
virtual void extensionsInitialized() override;
virtual ShutdownFlag aboutToShutdown() override;
QtCreatorDRPCPlugin();
virtual ~QtCreatorDRPCPlugin() override;
};
};
#endif // CUTEDISCORDPRESENCEPLUGIN_H