forked from sandsmark/selectdefaultapplication
-
Notifications
You must be signed in to change notification settings - Fork 3
/
selectdefaultapplication.h
92 lines (78 loc) · 2.89 KB
/
selectdefaultapplication.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
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QMimeDatabase>
#include <QMultiHash>
#include <QLabel>
#include <QPushButton>
#include <QToolButton>
#include <QLineEdit>
#include <QSet>
#include <QMenu>
class QFileInfo;
class QTreeWidget;
class QListWidget;
class QPushButton;
enum overwriteConfirm {
NON_DESTRUCTIVE,
OVERWRITE_ALL,
CANCEL_CHANGES,
};
class SelectDefaultApplication : public QWidget {
Q_OBJECT
public:
SelectDefaultApplication(QWidget *parent, bool isVerbose);
~SelectDefaultApplication();
private slots:
void onApplicationSelected();
void onSetDefaultClicked();
void populateApplicationList(const QString &filter);
void showHelp();
void constrictGroup(QAction *action);
void enableSetDefaultButton();
private:
void loadDesktopFile(const QFileInfo &fileInfo);
void setDefault(const QString &appName, QSet<QString> &mimetypes);
void loadIcons(const QString &path);
void addToMimetypeList(QListWidget *list, const QString &mimetypeName, const bool selected);
void readCurrentDefaultMimetypes();
bool applicationHasAnyCorrectMimetype(const QString &appName);
void onApplicationSelectedLogic(bool allowEnable);
const QString wrapperMimeTypeForName(const QString &name);
overwriteConfirm getOverwriteConfirmation(const QHash<QString, QString> &warnings);
const QString mimetypeDescription(QString name);
// Hashtable of application names to hashtables of mimetypes to .desktop file entries
QHash<QString, QHash<QString, QString> > m_apps;
// Hashtable of application names to icons
QHash<QString, QString> m_applicationIcons;
// Multi-hashtable with keys as parent mime types and values as all children of that mimetype which are encountered
QMultiHash<QString, QString> m_childMimeTypes;
// Set containing all the mimegroups we saw
QSet<QString> m_mimegroups;
// Global variable to match selected mimegroup on
QString m_filterMimegroup;
// Multi-hashtable with keys as mimetypes and values as application names
QHash<QString, QString> m_defaultApps;
// Multi-hashtable with keys as .desktop files and values as mimetypes, read from mimeapps.list
// Note this is opposite how they are actually stored. It is done this way so that we can read mimeapps.list before
// parsing anything else and then as we loop over all .desktop files, fill up the associations between programs and
// mimetypes. Remains constant after startup
QMultiHash<QString, QString> m_defaultDesktopEntries;
bool isVerbose;
// for preloading icons, because that's (a bit) slooow
QHash<QString, QIcon> m_mimeTypeIcons;
QHash<QString, QString> m_iconPaths;
QMimeDatabase m_mimeDb;
// UI elements
QListWidget *m_applicationList;
QListWidget *m_mimetypeList;
QListWidget *m_currentDefaultApps;
QLineEdit *m_searchBox;
QPushButton *m_groupChooser;
QMenu *m_mimegroupMenu;
QPushButton *m_setDefaultButton;
QToolButton *m_infoButton;
QLabel *m_middleBanner;
QLabel *m_rightBanner;
};
#endif // WIDGET_H