Compare commits
4 Commits
wip/inheri
...
5eb09540c6
Author | SHA1 | Date | |
---|---|---|---|
5eb09540c6 | |||
416bfa6314 | |||
edb781580e | |||
36b6390292 |
@ -75,12 +75,34 @@ EntryConfig EntryProvider::readFromDesktopFile(const QString &path)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(key == "nodisplay")
|
||||||
|
{
|
||||||
|
result.hidden = args == "true";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* qsrun own's config file */
|
std::optional<EntryConfig> EntryProvider::readEntryFromPath(const QString &path)
|
||||||
EntryConfig EntryProvider::readFromFile(const QString &path)
|
{
|
||||||
|
QFileInfo info(path);
|
||||||
|
if(info.isFile())
|
||||||
|
{
|
||||||
|
QString suffix = info.suffix();
|
||||||
|
if(suffix == "desktop")
|
||||||
|
{
|
||||||
|
return readFromDesktopFile(path);
|
||||||
|
}
|
||||||
|
if(suffix == "qsrun")
|
||||||
|
{
|
||||||
|
return readqsrunFile(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
/* qsrun's own format */
|
||||||
|
EntryConfig EntryProvider::readqsrunFile(const QString &path)
|
||||||
{
|
{
|
||||||
EntryConfig result;
|
EntryConfig result;
|
||||||
EntryConfig inheritedConfig;
|
EntryConfig inheritedConfig;
|
||||||
@ -159,7 +181,11 @@ EntryConfig EntryProvider::readFromFile(const QString &path)
|
|||||||
}
|
}
|
||||||
if(key == "inherit")
|
if(key == "inherit")
|
||||||
{
|
{
|
||||||
inheritedConfig = readFromDesktopFile(resolveEntryPath(splitted[1]));
|
auto entry = readEntryFromPath(resolveEntryPath(splitted[1]));
|
||||||
|
if(entry)
|
||||||
|
{
|
||||||
|
inheritedConfig = *entry;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result.update(inheritedConfig);
|
return result.update(inheritedConfig);
|
||||||
@ -197,17 +223,12 @@ QVector<EntryConfig> EntryProvider::readConfig(QStringList paths)
|
|||||||
while(it.hasNext())
|
while(it.hasNext())
|
||||||
{
|
{
|
||||||
QString path = it.next();
|
QString path = it.next();
|
||||||
QFileInfo info(path);
|
std::optional<EntryConfig> entry = readEntryFromPath(path);
|
||||||
if(info.isFile())
|
if(entry)
|
||||||
{
|
{
|
||||||
QString suffix = info.suffix();
|
if(!entry->hidden)
|
||||||
if(suffix == "desktop")
|
|
||||||
{
|
{
|
||||||
result.append(readFromDesktopFile(path));
|
result.append(*entry);
|
||||||
}
|
|
||||||
if(suffix == "qsrun")
|
|
||||||
{
|
|
||||||
result.append(readFromFile(path));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define ENTRYPROVIDER_H
|
#define ENTRYPROVIDER_H
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
class ConfigFormatException : public std::runtime_error
|
class ConfigFormatException : public std::runtime_error
|
||||||
{
|
{
|
||||||
@ -17,6 +18,7 @@ class ConfigFormatException : public std::runtime_error
|
|||||||
class EntryConfig
|
class EntryConfig
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
bool hidden = false;
|
||||||
QString key;
|
QString key;
|
||||||
QString name;
|
QString name;
|
||||||
QString command;
|
QString command;
|
||||||
@ -34,8 +36,9 @@ class EntryProvider
|
|||||||
QStringList _desktopIgnoreArgs;
|
QStringList _desktopIgnoreArgs;
|
||||||
QStringList userEntriesDirsPaths;
|
QStringList userEntriesDirsPaths;
|
||||||
QStringList systemEntriesDirsPaths;
|
QStringList systemEntriesDirsPaths;
|
||||||
EntryConfig readFromFile(const QString &path);
|
EntryConfig readqsrunFile(const QString &path);
|
||||||
EntryConfig readFromDesktopFile(const QString &path);
|
EntryConfig readFromDesktopFile(const QString &path);
|
||||||
|
std::optional<EntryConfig> readEntryFromPath(const QString &path);
|
||||||
QVector<EntryConfig> readConfig(QStringList paths);
|
QVector<EntryConfig> readConfig(QStringList paths);
|
||||||
QString resolveEntryPath(QString path);
|
QString resolveEntryPath(QString path);
|
||||||
|
|
||||||
|
@ -23,5 +23,5 @@ SOURCES += calculationengine.cpp \
|
|||||||
QT += widgets sql network
|
QT += widgets sql network
|
||||||
QT_CONFIG -= no-pkg-config
|
QT_CONFIG -= no-pkg-config
|
||||||
LIBS += -lcln
|
LIBS += -lcln
|
||||||
CONFIG += link_pkgconfig
|
CONFIG += link_pkgconfig c++17
|
||||||
PKGCONFIG += libqalculate
|
PKGCONFIG += libqalculate
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "settingsprovider.h"
|
#include "settingsprovider.h"
|
||||||
#include <QFileInfo>
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QFileInfo>
|
||||||
|
|
||||||
SettingsProvider::SettingsProvider(QSettings &settings)
|
SettingsProvider::SettingsProvider(QSettings &settings)
|
||||||
{
|
{
|
||||||
@ -19,9 +19,12 @@ QStringList SettingsProvider::systemApplicationsEntriesPaths() const
|
|||||||
return settings->value("sysAppsPaths", "/usr/share/applications/").toStringList();
|
return settings->value("sysAppsPaths", "/usr/share/applications/").toStringList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int SettingsProvider::getMaxCols() const
|
||||||
|
{
|
||||||
|
return settings->value("maxColumns", 3).toInt();
|
||||||
|
}
|
||||||
|
|
||||||
bool SettingsProvider::singleInstanceMode() const
|
bool SettingsProvider::singleInstanceMode() const
|
||||||
{
|
{
|
||||||
return settings->value("singleInstance", true).toBool();
|
return settings->value("singleInstance", true).toBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,17 +1,19 @@
|
|||||||
#ifndef SETTINGSPROVIDER_H
|
#ifndef SETTINGSPROVIDER_H
|
||||||
#define SETTINGSPROVIDER_H
|
#define SETTINGSPROVIDER_H
|
||||||
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
class SettingsProvider
|
class SettingsProvider
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
QSettings *settings;
|
QSettings *settings;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SettingsProvider(QSettings &settings);
|
SettingsProvider(QSettings &settings);
|
||||||
virtual QStringList userEntriesPaths() const;
|
virtual QStringList userEntriesPaths() const;
|
||||||
virtual QStringList systemApplicationsEntriesPaths() const;
|
virtual QStringList systemApplicationsEntriesPaths() const;
|
||||||
|
virtual int getMaxCols() const;
|
||||||
virtual bool singleInstanceMode() const;
|
virtual bool singleInstanceMode() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
43
window.cpp
43
window.cpp
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018-2019 Albert S. <mail at quitesimple dot org>
|
* Copyright (c) 2018-2020 Albert S. <mail at quitesimple dot org>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@ -13,22 +13,23 @@
|
|||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include <QProcess>
|
#include <QClipboard>
|
||||||
#include <QProcessEnvironment>
|
#include <QDate>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QDesktopServices>
|
||||||
#include <QDirIterator>
|
#include <QDirIterator>
|
||||||
|
#include <QFileIconProvider>
|
||||||
|
#include <QHeaderView>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QKeySequence>
|
#include <QKeySequence>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QDate>
|
|
||||||
#include <QHeaderView>
|
|
||||||
#include <QDesktopServices>
|
|
||||||
#include <QFileIconProvider>
|
|
||||||
#include <QDebug>
|
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QClipboard>
|
#include <QProcess>
|
||||||
|
#include <QProcessEnvironment>
|
||||||
#include <QScrollArea>
|
#include <QScrollArea>
|
||||||
#include "window.h"
|
|
||||||
#include "entryprovider.h"
|
#include "entryprovider.h"
|
||||||
|
#include "window.h"
|
||||||
Window::Window(EntryProvider &entryProvider, SettingsProvider &configProvider)
|
Window::Window(EntryProvider &entryProvider, SettingsProvider &configProvider)
|
||||||
{
|
{
|
||||||
this->entryProvider = &entryProvider;
|
this->entryProvider = &entryProvider;
|
||||||
@ -43,13 +44,12 @@ Window::Window(EntryProvider &entryProvider, SettingsProvider &configProvider)
|
|||||||
calculationResultLabel.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
calculationResultLabel.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
calculationResultLabel.setAlignment(Qt::AlignCenter);
|
calculationResultLabel.setAlignment(Qt::AlignCenter);
|
||||||
calculationResultLabel.setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu);
|
calculationResultLabel.setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu);
|
||||||
connect(&calculationResultLabel, &QLabel::customContextMenuRequested, this, &Window::showCalculationResultContextMenu);
|
connect(&calculationResultLabel, &QLabel::customContextMenuRequested, this,
|
||||||
|
&Window::showCalculationResultContextMenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
Window::~Window()
|
Window::~Window()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::initFromConfig()
|
void Window::initFromConfig()
|
||||||
@ -198,7 +198,6 @@ void Window::addCalcResult(const QString &expression)
|
|||||||
calculationResultLabel.setText(labelText);
|
calculationResultLabel.setText(labelText);
|
||||||
calculationResultLabel.setVisible(true);
|
calculationResultLabel.setVisible(true);
|
||||||
|
|
||||||
|
|
||||||
QFont currentFont = calculationResultLabel.font();
|
QFont currentFont = calculationResultLabel.font();
|
||||||
int calculatedPointSize = currentFont.pointSize();
|
int calculatedPointSize = currentFont.pointSize();
|
||||||
QFontMetrics fm(currentFont);
|
QFontMetrics fm(currentFont);
|
||||||
@ -268,11 +267,11 @@ void Window::keyReleaseEvent(QKeyEvent *event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
QWidget::keyReleaseEvent(event);
|
QWidget::keyReleaseEvent(event);
|
||||||
|
|
||||||
}
|
}
|
||||||
void Window::keyPressEvent(QKeyEvent *event)
|
void Window::keyPressEvent(QKeyEvent *event)
|
||||||
{
|
{
|
||||||
bool closeWindow = ((event->modifiers() & Qt::ControlModifier && event->key() == Qt::Key_Q) || event->key() == Qt::Key_Escape);
|
bool closeWindow =
|
||||||
|
((event->modifiers() & Qt::ControlModifier && event->key() == Qt::Key_Q) || event->key() == Qt::Key_Escape);
|
||||||
if(closeWindow)
|
if(closeWindow)
|
||||||
{
|
{
|
||||||
this->closeWindow();
|
this->closeWindow();
|
||||||
@ -294,7 +293,8 @@ void Window::keyPressEvent(QKeyEvent *event)
|
|||||||
QKeySequence seq(event->key());
|
QKeySequence seq(event->key());
|
||||||
QString key = seq.toString().toLower();
|
QString key = seq.toString().toLower();
|
||||||
|
|
||||||
auto it = std::find_if(buttonsInGrid.begin(), buttonsInGrid.end(), [&key](const EntryPushButton *y) { return y->getShortcutKey() == key; });
|
auto it = std::find_if(buttonsInGrid.begin(), buttonsInGrid.end(),
|
||||||
|
[&key](const EntryPushButton *y) { return y->getShortcutKey() == key; });
|
||||||
if(it != buttonsInGrid.end())
|
if(it != buttonsInGrid.end())
|
||||||
{
|
{
|
||||||
buttonClick(**it);
|
buttonClick(**it);
|
||||||
@ -324,6 +324,7 @@ void Window::filterGridFor(QString filter)
|
|||||||
int currow = 0;
|
int currow = 0;
|
||||||
int curcol = 0;
|
int curcol = 0;
|
||||||
int i = 1;
|
int i = 1;
|
||||||
|
const int MAX_COLS = this->settingsProvider->getMaxCols();
|
||||||
for(EntryPushButton *button : this->systemEntryButtons)
|
for(EntryPushButton *button : this->systemEntryButtons)
|
||||||
{
|
{
|
||||||
if(button->getName().contains(filter, Qt::CaseInsensitive))
|
if(button->getName().contains(filter, Qt::CaseInsensitive))
|
||||||
@ -335,7 +336,7 @@ void Window::filterGridFor(QString filter)
|
|||||||
}
|
}
|
||||||
grid->addWidget(button, currow, curcol++);
|
grid->addWidget(button, currow, curcol++);
|
||||||
this->buttonsInGrid.append(button);
|
this->buttonsInGrid.append(button);
|
||||||
if(curcol == 3)
|
if(curcol == MAX_COLS)
|
||||||
{
|
{
|
||||||
curcol = 0;
|
curcol = 0;
|
||||||
++currow;
|
++currow;
|
||||||
@ -343,15 +344,11 @@ void Window::filterGridFor(QString filter)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
populateGrid(this->userEntryButtons);
|
populateGrid(this->userEntryButtons);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EntryPushButton *Window::createEntryButton(const EntryConfig &entry)
|
EntryPushButton *Window::createEntryButton(const EntryConfig &entry)
|
||||||
@ -370,7 +367,6 @@ void Window::lineEditReturnPressed()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(buttonsInGrid.length() > 0 && this->lineEdit->text().length() > 0)
|
if(buttonsInGrid.length() > 0 && this->lineEdit->text().length() > 0)
|
||||||
{
|
{
|
||||||
buttonClick(*buttonsInGrid[0]);
|
buttonClick(*buttonsInGrid[0]);
|
||||||
@ -401,7 +397,6 @@ bool Window::eventFilter(QObject *obj, QEvent *event)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return QObject::eventFilter(obj, event);
|
return QObject::eventFilter(obj, event);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user