-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Launcher.cxx
98 lines (77 loc) · 2.55 KB
/
Launcher.cxx
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
/*
This file is part of liquidshell.
SPDX-FileCopyrightText: 2017 - 2024 Martin Koller <kollix@aon.at>
SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <Launcher.hxx>
#include <QVBoxLayout>
#include <QFileDialog>
#include <QAction>
#include <QCursor>
#include <QMenu>
#include <QIcon>
#include <QDebug>
#include <KConfig>
#include <KConfigGroup>
#include <KLocalizedString>
#include <KIO/OpenUrlJob>
#include <KIO/JobUiDelegateFactory>
//--------------------------------------------------------------------------------
Launcher::Launcher(QWidget *parent, const QString &theId)
: QWidget(parent), id(theId)
{
new QVBoxLayout(this);
layout()->setContentsMargins(QMargins());
}
//--------------------------------------------------------------------------------
void Launcher::loadConfig(const QString &defaultDir)
{
KConfig config;
KConfigGroup group = config.group(id);
setDir(group.readEntry(QString("dirPath"), defaultDir));
}
//--------------------------------------------------------------------------------
void Launcher::setDir(const QString &theDirPath)
{
if ( !dirWatcher.directories().isEmpty() )
dirWatcher.removePaths(dirWatcher.directories());
dirPath = theDirPath;
fill();
if ( !dirPath.isEmpty() )
{
dirWatcher.addPath(dirPath);
connect(&dirWatcher, &QFileSystemWatcher::directoryChanged, this, &Launcher::fill);
}
}
//--------------------------------------------------------------------------------
void Launcher::contextMenuEvent(QContextMenuEvent *event)
{
Q_UNUSED(event)
QMenu menu;
QAction *action = menu.addAction(QIcon::fromTheme("configure"), i18n("Configure..."));
connect(action, &QAction::triggered,
[this]()
{
QString path = QFileDialog::getExistingDirectory(this, QString(), dirPath);
if ( !path.isEmpty() )
{
KConfig config;
KConfigGroup group = config.group(id);
group.writeEntry(QString("dirPath"), path);
setDir(path);
}
}
);
if ( !dirPath.isEmpty() )
{
action = menu.addAction(QIcon::fromTheme("folder"), i18n("Open Folder"));
connect(action, &QAction::triggered, [this]()
{
KIO::OpenUrlJob *job = new KIO::OpenUrlJob(QUrl::fromLocalFile(dirPath));
job->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
job->start();
});
}
menu.exec(QCursor::pos());
}
//--------------------------------------------------------------------------------