Browse Source

Add a filename resolution method

Closes #11
tags/v5.0.0^2
ArsenArsen 5 years ago
parent
commit
4cf1c980c5
  1. 6
      KShare.pro
  2. 12
      filenamevalidator.cpp
  3. 12
      filenamevalidator.hpp
  4. 7
      platformbackend.hpp
  5. 4
      platformspecifics/mac/macbackend.cpp
  6. 1
      platformspecifics/mac/macbackend.hpp
  7. 4
      platformspecifics/u32/u32backend.cpp
  8. 1
      platformspecifics/u32/u32backend.hpp
  9. 4
      platformspecifics/x11/x11backend.cpp
  10. 1
      platformspecifics/x11/x11backend.hpp
  11. 2
      settingsdialog.cpp

6
KShare.pro

@ -65,7 +65,8 @@ SOURCES += main.cpp\
hotkeyinputdialog.cpp \
cropeditor/drawing/arrowitem.cpp \
uploaders/default/imgursettingsdialog.cpp \
uploaders/default/imgplusuploader.cpp
uploaders/default/imgplusuploader.cpp \
filenamevalidator.cpp
HEADERS += mainwindow.hpp \
cropeditor/cropeditor.hpp \
@ -109,7 +110,8 @@ HEADERS += mainwindow.hpp \
hotkeyinputdialog.hpp \
cropeditor/drawing/arrowitem.hpp \
uploaders/default/imgursettingsdialog.hpp \
uploaders/default/imgplusuploader.hpp
uploaders/default/imgplusuploader.hpp \
filenamevalidator.hpp
CONFIG += link_pkgconfig
PKGCONFIG += libavformat libavcodec libswscale libavutil

12
filenamevalidator.cpp

@ -0,0 +1,12 @@
#include "filenamevalidator.hpp"
#include <formatter.hpp>
#include <platformbackend.hpp>
FilenameValidator::FilenameValidator(QObject *parent) : QValidator(parent) {
}
QValidator::State FilenameValidator::validate(QString &input, int &) const {
QString name = formatter::format(input, "lol");
return PlatformBackend::inst().filenameValid(name) ? State::Acceptable : State::Invalid;
}

12
filenamevalidator.hpp

@ -0,0 +1,12 @@
#ifndef FILENAMEVALIDATOR_HPP
#define FILENAMEVALIDATOR_HPP
#include <QValidator>
class FilenameValidator : public QValidator {
public:
FilenameValidator(QObject *parent = nullptr);
QValidator::State validate(QString &input, int &) const override;
};
#endif // FILENAMEVALIDATOR_HPP

7
platformbackend.hpp

@ -1,13 +1,14 @@
#ifndef PLATFORMBACKEND_HPP
#define PLATFORMBACKEND_HPP
#include <QtGlobal>
#ifdef __APPLE__
#ifdef Q_OS_MACOS
#include <platformspecifics/mac/macbackend.hpp>
#endif
#ifdef _WIN32
#ifdef Q_OS_WIN
#include <platformspecifics/u32/u32backend.hpp>
#endif
#ifdef __unix__
#ifdef Q_OS_UNIX
#include <platformspecifics/x11/x11backend.hpp>
#endif

4
platformspecifics/mac/macbackend.cpp

@ -11,3 +11,7 @@ QPixmap PlatformBackend::getCursor() {
pid_t PlatformBackend::pid() {
return getpid();
}
bool PlatformBackend::filenameValid(QString name) {
return !name.contains('/');
}

1
platformspecifics/mac/macbackend.hpp

@ -13,6 +13,7 @@ public:
static PlatformBackend inst;
return inst;
}
bool filenameValid(QString name);
};
#endif // MACBACKEND_HPP

4
platformspecifics/u32/u32backend.cpp

@ -28,3 +28,7 @@ DWORD PlatformBackend::pid() {
WId PlatformBackend::getActiveWID() {
return (WId)GetForegroundWindow();
}
bool PlatformBackend::filenamValid(QString name) {
return IsValidFileName(name.toLocal8Bit().constData()) == 0;
}

1
platformspecifics/u32/u32backend.hpp

@ -17,6 +17,7 @@ public:
return inst;
}
WId getActiveWID();
bool filenamValid(QString name);
};
#endif // U32BACKEND_HPP

4
platformspecifics/x11/x11backend.cpp

@ -54,3 +54,7 @@ WId PlatformBackend::getActiveWID() {
delete treeReply;
return window;
}
bool PlatformBackend::filenameValid(QString name) {
return !name.contains('/');
}

1
platformspecifics/x11/x11backend.hpp

@ -16,6 +16,7 @@ public:
return inst;
}
WId getActiveWID();
bool filenameValid(QString name);
};
#endif // X11BACKEND_HPP

2
settingsdialog.cpp

@ -1,4 +1,5 @@
#include "settingsdialog.hpp"
#include "filenamevalidator.hpp"
#include "hotkeyinputdialog.hpp"
#include "mainwindow.hpp"
#include "ui_settingsdialog.h"
@ -77,6 +78,7 @@ SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent), ui(new Ui::Se
ui->cropX->setValue(settings::settings().value("cropx", 0).toInt());
ui->cropY->setValue(settings::settings().value("cropy", 0).toInt());
setWindowTitle("Settings");
ui->nameScheme->setValidator(new FilenameValidator(ui->nameScheme));
#ifndef PLATFORM_CAPABILITY_CURSOR
ui->captureCursor->setEnabled(false);
ui->captureCursor->setText("Capture cursor (disabled: implementation missing)");

Loading…
Cancel
Save