3 커밋

15개의 변경된 파일119개의 추가작업 그리고 287개의 파일을 삭제

파일 보기

@ -13,11 +13,6 @@ EntryProvider::EntryProvider(QStringList userEntriesDirsPaths, QStringList syste
<< "%u";
}
bool EntryProvider::isSavable(const EntryConfig &config) const
{
return ! config.entryPath.isEmpty() && (config.type == EntryType::USER || config.type == EntryType::INHERIT);
}
EntryConfig EntryProvider::readFromDesktopFile(const QString &path)
{
EntryConfig result;
@ -25,7 +20,7 @@ EntryConfig EntryProvider::readFromDesktopFile(const QString &path)
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
// TODO: better exception class
throw std::runtime_error("Failed to open file");
throw new std::runtime_error("Failed to open file");
}
QTextStream stream(&file);
// There should be nothing preceding this group in the desktop entry file but possibly one or more comments.
@ -120,7 +115,7 @@ EntryConfig EntryProvider::readqsrunFile(const QString &path)
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
// TODO: better exception class
throw std::runtime_error("Failed to open file");
throw new std::runtime_error("Failed to open file");
}
QHash<QString, QString> map;
QTextStream stream(&file);
@ -131,7 +126,7 @@ EntryConfig EntryProvider::readqsrunFile(const QString &path)
int spacePos = line.indexOf(' ');
if(spacePos == -1)
{
throw ConfigFormatException("misformated line in .qsrun config file " + path.toStdString());
throw new ConfigFormatException("misformated line in .qsrun config file " + path.toStdString());
}
QString key = line.mid(0, spacePos);
@ -139,7 +134,7 @@ EntryConfig EntryProvider::readqsrunFile(const QString &path)
if(key == "" || value == "")
{
throw ConfigFormatException("empty key or value in .qsrun config file " + path.toStdString());
throw new ConfigFormatException("empty key or value in .qsrun config file " + path.toStdString());
}
map[key] = value;
}
@ -154,7 +149,7 @@ EntryConfig EntryProvider::readqsrunFile(const QString &path)
}
else
{
throw ConfigFormatException("Error attempting to read inherited entry");
throw new ConfigFormatException("Error attempting to read inherited entry");
}
}
QString type = map["type"];
@ -162,7 +157,7 @@ EntryConfig EntryProvider::readqsrunFile(const QString &path)
{
if(type == "system")
{
throw ConfigFormatException(".qsrun files cannot be designated as system entries " +
throw new ConfigFormatException(".qsrun files cannot be designated as system entries " +
path.toStdString());
}
else if(type == "inherit")
@ -175,7 +170,7 @@ EntryConfig EntryProvider::readqsrunFile(const QString &path)
}
else
{
throw ConfigFormatException("Invalid value for type provided in file: " + path.toStdString());
throw new ConfigFormatException("Invalid value for type provided in file: " + path.toStdString());
}
}
else
@ -290,7 +285,7 @@ QVector<EntryConfig> EntryProvider::getSystemEntries()
void EntryProvider::saveUserEntry(const EntryConfig &config)
{
if(!isSavable(config))
if(config.type == EntryType::SYSTEM || config.entryPath.isEmpty())
{
throw std::runtime_error("Only user/inherited entries can be saved");
}
@ -301,35 +296,32 @@ void EntryProvider::saveUserEntry(const EntryConfig &config)
throw std::runtime_error("Error: Can not open file for writing");
}
QTextStream outStream(&file);
outStream << "type" << " " << ((config.type == EntryType::USER) ? "user" : "inherit") << Qt::endl;
outStream << "type" << " " << ((config.type == EntryType::USER) ? "user" : "inherit") << endl;
if(!config.inherit.isEmpty())
{
outStream << "inherit" << " " << config.inherit << Qt::endl;
}
outStream << "row" << " " << config.row << Qt::endl;
outStream << "col" << " " << config.col << Qt::endl;
outStream << "hidden" << " " << config.hidden << Qt::endl;
if(!config.key.isEmpty())
{
outStream << "key" << " " << config.key << Qt::endl;
outStream << "inherit" << " " << config.inherit << endl;
}
outStream << "row" << " " << config.row << endl;
outStream << "col" << " " << config.col << endl;
outStream << "hidden" << " " << config.hidden << endl;
outStream << "key" << " " << config.key << endl;
if(config.type == EntryType::USER)
{
if(!config.name.isEmpty())
{
outStream << "name" << " " << config.name << Qt::endl;
outStream << "name" << " " << config.name << endl;
}
if(!config.command.isEmpty())
{
outStream << "command" << " " << config.command << Qt::endl;
outStream << "command" << " " << config.command << endl;
}
if(!config.iconPath.isEmpty())
{
outStream << "icon" << " " << config.iconPath << Qt::endl;
outStream << "icon" << " " << config.iconPath << endl;
}
if(!config.arguments.empty())
{
outStream << "arguments" << " " << config.arguments.join(' ') << Qt::endl;
outStream << "arguments" << " " << config.arguments.join(' ') << endl;
}
}
@ -347,7 +339,7 @@ void EntryProvider::saveUserEntry(const EntryConfig &config)
bool EntryProvider::deleteUserEntry(const EntryConfig &config)
{
if(!isSavable(config))
if(config.type == EntryType::SYSTEM || config.entryPath.isEmpty())
{
throw std::runtime_error("Only user/inherited entries can be deleted");
}

파일 보기

@ -19,8 +19,7 @@ enum EntryType
{
USER,
INHERIT,
SYSTEM,
DYNAMIC
SYSTEM
};
class EntryConfig
@ -56,7 +55,6 @@ class EntryProvider
public:
EntryProvider(QStringList userEntriesDirsPaths, QStringList systemEntriesDirsPaths);
bool isSavable(const EntryConfig &config) const;
QVector<EntryConfig> getUserEntries();
QVector<EntryConfig> getSystemEntries();
void saveUserEntry(const EntryConfig &config);

파일 보기

@ -33,7 +33,19 @@ EntryPushButton::EntryPushButton(const EntryConfig &config) : QPushButton()
icon = resolveIcon(config.iconPath);
}
this->setIcon(icon);
this->setIconSize(QSize{256, 256});
if(!icon.availableSizes().isEmpty())
{
auto sizes = icon.availableSizes();
QSize maxSize = sizes.first();
for(QSize &current : sizes)
{
if(current.width() > maxSize.width())
{
maxSize = current;
}
}
this->setIconSize(maxSize);
}
this->config = config;
connect(this, SIGNAL(clicked()), this, SLOT(emitOwnClicked()));
@ -94,7 +106,7 @@ void EntryPushButton::mousePressEvent(QMouseEvent *event)
{
this->userEntryMenu.exec(QCursor::pos());
}
else if(this->config.type == EntryType::SYSTEM)
else
{
this->systemEntryMenu.exec(QCursor::pos());
}
@ -104,7 +116,7 @@ void EntryPushButton::mousePressEvent(QMouseEvent *event)
void EntryPushButton::mouseMoveEvent(QMouseEvent *event)
{
if(this->config.type == EntryType::SYSTEM || this->config.type == EntryType::DYNAMIC)
if(this->config.type == EntryType::SYSTEM)
{
return;
}

파일 보기

@ -14,7 +14,6 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <QApplication>
#include <QCommandLineParser>
#include <QFuture>
#include <QFutureWatcher>
#include <QtConcurrent/QtConcurrentRun>
@ -31,76 +30,56 @@ int main(int argc, char *argv[])
QApplication app(argc, argv);
QString configDirectoryPath;
QDir dir;
bool newInstanceRequested = false;
if(argc >= 2)
{
QCommandLineParser parser;
parser.addOptions({
{"new-instance", "Launch a new instance, ignoring any running ones"},
{"config", "Use supplied config dir instead of default"},
});
parser.addHelpOption();
parser.process(app.arguments());
configDirectoryPath = parser.value("config");
newInstanceRequested = parser.isSet("new-instance");
if(!configDirectoryPath.isEmpty() && !dir.exists(configDirectoryPath))
configDirectoryPath = QCoreApplication::arguments().at(1);
if(!dir.exists(configDirectoryPath))
{
QMessageBox::warning(nullptr, "Directory not found", configDirectoryPath + " was not found");
return 1;
}
}
if(configDirectoryPath.isEmpty())
else
{
configDirectoryPath = QDir::homePath() + "/.config/qsrun/";
}
qRegisterMetaType<QVector<QString> >("QVector<QString>");
qRegisterMetaType<QVector<QString>>("QVector<QString>");
if(!dir.exists(configDirectoryPath))
{
if(!dir.mkdir(configDirectoryPath))
{
QMessageBox::warning(nullptr, "Failed to create dir",
configDirectoryPath + " was not found and could not be created!");
QMessageBox::warning(nullptr, "Failed to create dir", configDirectoryPath + " was not found and could not be created!");
return 1;
}
}
QSettings settings(configDirectoryPath + "qsrun.config", QSettings::NativeFormat);
SettingsProvider settingsProvider{settings};
SettingsProvider settingsProvider { settings };
EntryProvider entryProvider(settingsProvider.userEntriesPaths(), settingsProvider.systemApplicationsEntriesPaths());
SingleInstanceServer *server = nullptr;
bool singleInstanceMode = !newInstanceRequested && settingsProvider.singleInstanceMode();
if(singleInstanceMode)
//TODO if setting single instance mode
QLocalSocket localSocket;
localSocket.connectToServer("/tmp/qsrun.socket");
SingleInstanceServer server;
if(localSocket.isOpen() && localSocket.isWritable())
{
QLocalSocket localSocket;
localSocket.connectToServer(settingsProvider.socketPath());
if(localSocket.isOpen() && localSocket.isWritable())
{
QDataStream stream(&localSocket);
stream << (int)0x01; // maximize
localSocket.flush();
localSocket.waitForBytesWritten();
localSocket.disconnectFromServer();
return 0;
}
server = new SingleInstanceServer();
if(!server->listen(settingsProvider.socketPath()))
QDataStream stream(&localSocket);
stream << (int)0x01; //maximize
localSocket.flush();
localSocket.waitForBytesWritten();
localSocket.disconnectFromServer();
return 0;
}
else
{
if(!server.listen("/tmp/qsrun.socket"))
{
qDebug() << "Failed to listen on socket!";
return 1;
}
}
Window *w = new Window{entryProvider, settingsProvider};
if(singleInstanceMode && server != nullptr)
{
QObject::connect(server, &SingleInstanceServer::receivedMaximizationRequest, [&w] {
Window *w = new Window { entryProvider, settingsProvider };
QObject::connect(&server, &SingleInstanceServer::receivedMaximizationRequest, [&w]{
if(w != nullptr)
{
qInfo() << "maximizing as requested by other instance";
@ -110,10 +89,12 @@ int main(int argc, char *argv[])
w->focusInput();
}
});
w->showMaximized();
w->focusInput();
}
w->showMaximized();
w->focusInput();
return app.exec();
}

파일 보기

@ -12,8 +12,6 @@ HEADERS += calculationengine.h \
entrypushbutton.h \
settingsprovider.h \
singleinstanceserver.h \
specialcommandconfig.h \
textoutputlabel.h \
window.h
SOURCES += calculationengine.cpp \
entryprovider.cpp \
@ -21,7 +19,6 @@ SOURCES += calculationengine.cpp \
main.cpp \
settingsprovider.cpp \
singleinstanceserver.cpp \
textoutputlabel.cpp \
window.cpp
QT += widgets sql network
QT_CONFIG -= no-pkg-config

Binary file not shown.

Before

Width:  |  Height:  |  크기: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  크기: 48 KiB

BIN
screenshots/startview.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  크기: 112 KiB

Binary file not shown.

Before

Width:  |  Height:  |  크기: 205 KiB

파일 보기

@ -33,33 +33,3 @@ QString SettingsProvider::getTerminalCommand() const
{
return settings->value("terminal", "/usr/bin/x-terminal-emulator -e %c").toString();
}
QString SettingsProvider::socketPath() const
{
return settings->value("singleInstanceSocket", "/tmp/qsrun").toString();
}
QVector<SpecialCommandConfig> SettingsProvider::specialCommands() const
{
QVector<SpecialCommandConfig> result;
SpecialCommandConfig uname;
uname.command = "uname";
uname.reqArgCount = 0;
uname.immediateProcessing = true;
result.append(uname);
SpecialCommandConfig date;
date.command = "date";
date.reqArgCount = 0;
date.immediateProcessing = true;
result.append(date);
SpecialCommandConfig echo;
echo.command = "echo";
echo.reqArgCount = 0;
echo.immediateProcessing = true;
result.append(echo);
return result;
}

파일 보기

@ -3,7 +3,6 @@
#include <QSettings>
#include <stdexcept>
#include "specialcommandconfig.h"
class SettingsProvider
{
@ -17,8 +16,6 @@ class SettingsProvider
virtual int getMaxCols() const;
virtual bool singleInstanceMode() const;
QString getTerminalCommand() const;
QString socketPath() const;
QVector<SpecialCommandConfig> specialCommands() const;
};
#endif // SETTINGSPROVIDER_H

파일 보기

@ -1,37 +0,0 @@
#include "textoutputlabel.h"
TextoutputLabel::TextoutputLabel()
{
QFont font;
font.setPointSize(48);
font.setBold(true);
this->setFont(font);
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
this->setAlignment(Qt::AlignCenter);
this->setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu);
}
void TextoutputLabel::setText(const QString &text)
{
QLabel::setText(text);
QFont currentFont = this->font();
int calculatedPointSize = currentFont.pointSize();
QFontMetrics fm(currentFont);
int contentWidth = this->contentsRect().width() - this->margin();
while(calculatedPointSize < 48 && fm.boundingRect(this->text()).width() < contentWidth)
{
calculatedPointSize += 1;
currentFont.setPointSize(calculatedPointSize);
fm = QFontMetrics(currentFont);
}
while(fm.boundingRect(this->text()).width() >= contentWidth)
{
calculatedPointSize -= 1;
currentFont.setPointSize(calculatedPointSize);
fm = QFontMetrics(currentFont);
}
this->setFont(currentFont);
}

파일 보기

@ -1,14 +0,0 @@
#ifndef TEXTOUTPUTLABEL_H
#define TEXTOUTPUTLABEL_H
#include <QLabel>
class TextoutputLabel : public QLabel
{
public:
TextoutputLabel();
virtual void setText(const QString &text);
};
#endif // TEXTOUTPUTLABEL_H

파일 보기

@ -30,7 +30,6 @@
#include "entryprovider.h"
#include "window.h"
Window::Window(EntryProvider &entryProvider, SettingsProvider &configProvider)
{
this->entryProvider = &entryProvider;
@ -39,7 +38,13 @@ Window::Window(EntryProvider &entryProvider, SettingsProvider &configProvider)
initFromConfig();
this->lineEdit->installEventFilter(this);
this->setAcceptDrops(true);
QFont font;
font.setPointSize(48);
font.setBold(true);
calculationResultLabel.setFont(font);
calculationResultLabel.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
calculationResultLabel.setAlignment(Qt::AlignCenter);
calculationResultLabel.setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu);
connect(&calculationResultLabel, &QLabel::customContextMenuRequested, this,
&Window::showCalculationResultContextMenu);
}
@ -54,7 +59,6 @@ void Window::initFromConfig()
{
this->userEntryButtons = generateEntryButtons(entryProvider->getUserEntries());
this->systemEntryButtons = generateEntryButtons(entryProvider->getSystemEntries());
this->specialCommands = settingsProvider->specialCommands();
}
catch(const ConfigFormatException &e)
{
@ -116,12 +120,11 @@ void Window::populateGrid(const QVector<EntryPushButton *> &list)
void Window::executeConfig(const EntryConfig &config)
{
if(config.isTerminalCommand || QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier))
if(config.isTerminalCommand)
{
QString cmd = settingsProvider->getTerminalCommand();
cmd.replace("%c", config.command);
QStringList args = QProcess::splitCommand(cmd);
QProcess::startDetached(args[0], args);
cmd.replace("%c", config.command + " " + config.arguments.join(' '));
QProcess::startDetached(cmd);
}
else
{
@ -163,7 +166,6 @@ void Window::addToFavourites(const EntryConfig &config)
when we add it to the favourites. the alternative would be to reload the whole config,
but that's probably overkill. */
userConfig.update(config);
userConfig.key = "";
userEntryButtons.append(createEntryButton(userConfig));
}
@ -263,7 +265,6 @@ void Window::addPATHSuggestion(const QString &text)
e.row = 0;
e.command = suggestions[0];
e.iconPath = suggestions[0];
e.type = EntryType::DYNAMIC;
EntryPushButton *button = createEntryButton(e);
clearGrid();
grid->addWidget(button, 0, 0);
@ -283,22 +284,34 @@ void Window::clearGrid()
buttonsInGrid.clear();
}
void Window::showGrowingOutputText(QString text)
{
clearGrid();
calculationResultLabel.setText(text);
calculationResultLabel.setVisible(true);
grid->addWidget(&calculationResultLabel, 0, 0);
}
void Window::addCalcResult(const QString &expression)
{
clearGrid();
currentCalculationResult = calcEngine.evaluate(expression);
QString labelText = expression + ": " + currentCalculationResult;
showGrowingOutputText(labelText);
calculationResultLabel.setText(labelText);
calculationResultLabel.setVisible(true);
QFont currentFont = calculationResultLabel.font();
int calculatedPointSize = currentFont.pointSize();
QFontMetrics fm(currentFont);
int contentWidth = calculationResultLabel.contentsRect().width() - calculationResultLabel.margin();
while(calculatedPointSize < 48 && fm.boundingRect(labelText).width() < contentWidth)
{
calculatedPointSize += 1;
currentFont.setPointSize(calculatedPointSize);
fm = QFontMetrics(currentFont);
}
while(fm.boundingRect(labelText).width() >= contentWidth)
{
calculatedPointSize -= 1;
currentFont.setPointSize(calculatedPointSize);
fm = QFontMetrics(currentFont);
}
calculationResultLabel.setFont(currentFont);
grid->addWidget(&calculationResultLabel, 0, 0);
}
// main problem here there is no easy event compression (clearing emit queue and only processing the last one)
@ -320,20 +333,15 @@ void Window::lineEditTextChanged(QString text)
addPATHSuggestion(text);
if(this->grid->count() == 0)
{
QStringList arguments = QProcess::splitCommand(text);
QString command = arguments[0];
auto specialCommandConfig = getSpecialCommandConfig(command);
if(specialCommandConfig)
{
executeSpecialCommand(specialCommandConfig.value(), arguments);
return;
}
QStringList arguments = text.split(" ");
EntryConfig e;
e.name = "Execute: " + text;
e.command = command;
e.arguments = arguments;
if(arguments.length() > 1)
{
e.arguments = arguments.mid(1);
}
e.command = arguments[0];
e.iconPath = "utilities-terminal";
e.type = EntryType::DYNAMIC;
EntryPushButton *button = createEntryButton(e);
clearGrid();
@ -373,10 +381,7 @@ void Window::keyPressEvent(QKeyEvent *event)
for(EntryPushButton *button : buttonsInGrid)
{
if(!button->getEntryConfig().key.isEmpty())
{
button->showShortcut();
}
button->showShortcut();
}
QKeySequence seq(event->key());
@ -392,49 +397,6 @@ void Window::keyPressEvent(QKeyEvent *event)
QWidget::keyPressEvent(event);
}
int Window::rankConfig(const EntryConfig &config, QString filter) const
{
if(config.name.startsWith(filter, Qt::CaseInsensitive))
{
return 0;
}
else if(config.command.startsWith(filter, Qt::CaseInsensitive))
{
return 1;
}
else if(config.name.contains(filter, Qt::CaseInsensitive))
{
return 2;
}
else if(config.command.contains(filter, Qt::CaseInsensitive))
{
return 3;
}
return -1;
}
std::optional<SpecialCommandConfig> Window::getSpecialCommandConfig(QString cmd) const
{
SpecialCommandConfig result;
for(const SpecialCommandConfig &config : this->specialCommands)
{
if(config.command == cmd)
{
return config;
}
}
return { };
}
void Window::executeSpecialCommand(const SpecialCommandConfig &config, QStringList arguments)
{
QProcess process;
process.start(config.command, arguments.mid(1));
process.waitForFinished();
QString result = process.readAllStandardOutput();
showGrowingOutputText(result);
}
void Window::filterGridFor(QString filter)
{
if(filter.length() > 0)
@ -443,8 +405,7 @@ void Window::filterGridFor(QString filter)
bool userEntryMatch = false;
for(EntryPushButton *button : this->userEntryButtons)
{
if(button->getName().contains(filter, Qt::CaseInsensitive) ||
button->getCommand().contains(filter, Qt::CaseInsensitive))
if(button->getName().contains(filter, Qt::CaseInsensitive))
{
button->setVisible(true);
grid->addWidget(button, button->getRow(), button->getCol());
@ -454,38 +415,26 @@ void Window::filterGridFor(QString filter)
}
if(!userEntryMatch)
{
QVector<RankedButton> rankedEntries;
int currow = 0;
int curcol = 0;
int i = 1;
const int MAX_COLS = this->settingsProvider->getMaxCols();
for(EntryPushButton *button : this->systemEntryButtons)
{
int ranking = rankConfig(button->getEntryConfig(), filter);
if(ranking > -1)
if(button->getName().contains(filter, Qt::CaseInsensitive))
{
RankedButton rb;
rb.button = button;
rb.ranking = ranking;
rankedEntries.append(rb);
}
}
std::sort(rankedEntries.begin(), rankedEntries.end(),
[](const RankedButton &a, const RankedButton &b) -> bool { return a.ranking < b.ranking; });
for(RankedButton &rankedButton : rankedEntries)
{
EntryPushButton *button = rankedButton.button;
button->setVisible(true);
if(i < 10)
{
button->setShortcutKey(QString::number(i++));
}
grid->addWidget(button, currow, curcol++);
this->buttonsInGrid.append(button);
if(curcol == MAX_COLS)
{
curcol = 0;
++currow;
button->setVisible(true);
if(i < 10)
{
button->setShortcutKey(QString::number(i++));
}
grid->addWidget(button, currow, curcol++);
this->buttonsInGrid.append(button);
if(curcol == MAX_COLS)
{
curcol = 0;
++currow;
}
}
}
}

파일 보기

@ -36,15 +36,6 @@
#include "entrypushbutton.h"
#include "calculationengine.h"
#include "settingsprovider.h"
#include "specialcommandconfig.h"
#include "textoutputlabel.h"
class RankedButton
{
public:
EntryPushButton *button = nullptr;
int ranking;
};
class Window : public QWidget
{
@ -61,8 +52,7 @@ class Window : public QWidget
QVector<EntryPushButton *> userEntryButtons;
QVector<EntryPushButton *> systemEntryButtons;
QVector<EntryPushButton *> buttonsInGrid;
QVector<SpecialCommandConfig> specialCommands;
TextoutputLabel calculationResultLabel;
QLabel calculationResultLabel;
QString currentCalculationResult;
QString queuedFileSearch;
QString queuedContentSearch;
@ -87,11 +77,8 @@ class Window : public QWidget
QStringList generatePATHSuggestions(const QString &text);
void closeWindow();
std::pair<int, int> getNextFreeCell();
int rankConfig(const EntryConfig &config, QString filter) const;
std::optional<SpecialCommandConfig> getSpecialCommandConfig(QString cmd) const;
void executeSpecialCommand(const SpecialCommandConfig &config, QStringList arguments);
void showGrowingOutputText(QString text);
private slots:
private slots:
void lineEditReturnPressed();
void showCalculationResultContextMenu(const QPoint &point);