summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregor Mi <codeminister@publicstatic.de>2014-01-20 19:12:34 (GMT)
committerGregor Mi <codeminister@publicstatic.de>2014-01-20 19:12:34 (GMT)
commitc6543cc5d9fcda986ae34a111fb7cf3bfa5c1423 (patch)
tree40e89ef9b7c3d192c5ad8edfe4668646b8365617
parent277950c3e30420ab4eafe67b5d2b2042afb26307 (diff)
Use frameworks cmake templates. Compiles but runtime error (see FIXMEs).
-rw-r--r--CMakeLists.txt37
-rw-r--r--autotests/CMakeLists.txt16
-rw-r--r--src/CMakeLists.txt3
-rw-r--r--src/SaveLocation.cpp15
-rw-r--r--src/SaveLocation.h5
-rw-r--r--src/main.cpp70
-rw-r--r--src/skanlite.cpp62
-rw-r--r--src/skanlite.h12
-rw-r--r--tests/CMakeLists.txt15
9 files changed, 147 insertions, 88 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 47fd4aa..4d0fa90 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -19,15 +19,25 @@ include(GenerateExportHeader)
find_package(Qt5 ${REQUIRED_QT_VERSION} NO_MODULE REQUIRED Core Widgets)
+# be not so strict with the poor developer who just wants to use strings
+remove_definitions(-DQT_NO_CAST_TO_ASCII)
+remove_definitions(-DQT_NO_CAST_FROM_ASCII)
+remove_definitions(-DQT_NO_URL_CAST_FROM_STRING)
+remove_definitions(-DQT_NO_CAST_FROM_BYTEARRAY)
+
+set(KF5_VERSION "5.0.0")
+
find_package(KF5 ${KF5_VERSION} REQUIRED
COMPONENTS # alias to find_package(KFGuiAddons ${KF5_VERSION} REQUIRED)
GuiAddons
+ I18n
+ Wallet # FIXME KF5 why is this needed?
+ PrintUtils # FIXME KF5 why is this needed?
DocTools # yields kdoctools_create_handbook
Sane # will find KF5Sane
+ KDE4Support # FIXME KF5 remove
)
-set(KF5_VERSION "5.0.0")
-
ecm_setup_version(
${KF5_VERSION}
VARIABLE_PREFIX SKANLITE
@@ -35,15 +45,28 @@ ecm_setup_version(
PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/src/version.h.cmake"
)
-message(STATUS "KSANE_FOUND=${KSANE_FOUND}, KSANE_INCLUDE_DIR=${KSANE_INCLUDE_DIR}")
-find_package(PNG REQUIRED)
+# Dependencies
+set(REQUIRED_QT_VERSION "5.2.0")
-set(SKANLITE_VERSION_MAJOR "1")
-set(SKANLITE_VERSION_MINOR "1")
-set(SKANLITE_VERSION_STRING "${SKANLITE_VERSION_MAJOR}.${SKANLITE_VERSION_MINOR}")
+# Required Qt5 components to build this framework
+find_package(Qt5 ${REQUIRED_QT_VERSION} NO_MODULE REQUIRED Core)
+find_package(PNG REQUIRED)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/version.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/src/version.h)
+# TODO: Add all required find_package() calls here
+
+# Subdirectories
add_subdirectory(src)
add_subdirectory(doc)
+add_subdirectory(autotests)
+add_subdirectory(tests)
+
+# FIXME KF5 review the stuff below later
+
+message(STATUS "KSANE_FOUND=${KSANE_FOUND}, KSANE_INCLUDE_DIR=${KSANE_INCLUDE_DIR}")
+
+set(SKANLITE_VERSION_MAJOR "1")
+set(SKANLITE_VERSION_MINOR "1")
+set(SKANLITE_VERSION_STRING "${SKANLITE_VERSION_MAJOR}.${SKANLITE_VERSION_MINOR}")
diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt
new file mode 100644
index 0000000..ebeeee6
--- /dev/null
+++ b/autotests/CMakeLists.txt
@@ -0,0 +1,16 @@
+find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Test)
+
+include(ECMMarkAsTest)
+
+macro(skanlite_tests)
+ foreach(_testname ${ARGN})
+ add_executable(${_testname} ${_testname}.cpp)
+ target_link_libraries(${_testname} Qt5::Test KF5skanlite)
+ add_test(skanlite-${_testname} ${_testname})
+ ecm_mark_as_test(${_testname})
+ endforeach(_testname)
+endmacro()
+
+#skanlite_tests(
+# skanlitetest
+#)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 1824429..22c3f94 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -16,8 +16,9 @@ target_link_libraries(skanlite
KF5::I18n
KF5::PrintUtils
KF5::Wallet
- KF5::WidgetsAddons
+ #KF5::WidgetsAddons
${PNG_LIBRARY}
+ KF5::KDE4Support # FIXME KF5: remove that later
)
install(TARGETS skanlite ${INSTALL_TARGETS_DEFAULT_ARGS})
diff --git a/src/SaveLocation.cpp b/src/SaveLocation.cpp
index c6e0196..e2a2115 100644
--- a/src/SaveLocation.cpp
+++ b/src/SaveLocation.cpp
@@ -3,6 +3,7 @@
* Description : Save location settings dialog.
*
* Copyright (C) 2010-2012 by Kare Sars <kare.sars@iki.fi>
+* Copyright (C) 2014 by Gregor Mitsch: port to KDE5 frameworks
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -23,16 +24,15 @@
* ============================================================ */
#include "SaveLocation.h"
-#include "SaveLocation.moc"
-#include <KDebug>
-#include <KFileDialog>
+#include <QDebug>
+#include <QFileDialog>
-SaveLocation::SaveLocation(QWidget *parent) : KDialog(parent)
+SaveLocation::SaveLocation(QWidget *parent) : QDialog(parent)
{
QWidget *container = new QWidget(this);
setupUi(container);
- setMainWidget(container);
+ //setMainWidget(container); // FIXME KF5 needed or remove?
connect(u_saveDirLEdit, SIGNAL(textChanged(QString)), this, SLOT(update()));
connect(u_imgPrefix, SIGNAL(textChanged(QString)), this, SLOT(update()));
connect(u_imgFormat, SIGNAL(activated(QString)), this, SLOT(update()));
@@ -40,12 +40,10 @@ SaveLocation::SaveLocation(QWidget *parent) : KDialog(parent)
connect(u_getDirButton, SIGNAL(clicked()), this, SLOT(getDir()));
}
-// ------------------------------------------------------------------------
SaveLocation::~SaveLocation()
{
}
-// ------------------------------------------------------------------------
void SaveLocation::update()
{
if (sender() != u_numStartFrom) {
@@ -55,10 +53,9 @@ void SaveLocation::update()
u_resultValue->setText(QFileInfo(u_saveDirLEdit->text(), name).absoluteFilePath());
}
-// ------------------------------------------------------------------------
void SaveLocation::getDir(void)
{
- QString newDir = KFileDialog::getExistingDirectory(u_saveDirLEdit->text());
+ QString newDir = QFileDialog::getExistingDirectory(this, QString(), u_saveDirLEdit->text());
if (!newDir.isEmpty()) {
u_saveDirLEdit->setText(newDir);
}
diff --git a/src/SaveLocation.h b/src/SaveLocation.h
index e6da055..c733cff 100644
--- a/src/SaveLocation.h
+++ b/src/SaveLocation.h
@@ -28,9 +28,9 @@
#include "ui_SaveLocation.h"
-#include <KDialog>
+#include <QDialog>
-class SaveLocation : public KDialog, public Ui_SaveLocation
+class SaveLocation : public QDialog, public Ui_SaveLocation
{
Q_OBJECT
public:
@@ -40,7 +40,6 @@ public:
private Q_SLOTS:
void update();
void getDir();
-
};
#endif
diff --git a/src/main.cpp b/src/main.cpp
index 6d3df94..cbb7169 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,6 +1,7 @@
/* ============================================================
*
* Copyright (C) 2007-2012 by Kåre Särs <kare.sars@iki .fi>
+* Copyright (C) 2014 by Gregor Mitsch: port to KDE5 frameworks
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -30,55 +31,54 @@
int main(int argc, char *argv[])
{
// about data
- KAboutData aboutData("Skanlite", "skanlite", ki18n("Skanlite"), skanlite_version,
- ki18n("This is a scanning application for KDE based on libksane."),
- KAboutData::License_GPL,
- ki18n("(C) 2008-2014 Kåre Särs"));
+ KAboutData aboutData("Skanlite", // appname
+ "skanlite", // catalogName
+ i18n("Skanlite"), // rogramName
+ skanlite_version, // version
+ i18n("This is a scanning application for KDE based on libksane."), // shortDescription
+ KAboutData::License_GPL, // licenseType
+ i18n("(C) 2008-2014 Kåre Särs") // copyrightStatement
+ );
- aboutData.addAuthor(ki18n("Kåre Särs"),
- ki18n("developer"),
- "kare.sars@iki.fi", 0);
+ aboutData.addAuthor(i18n("Kåre Särs"),
+ i18n("developer"),
+ "kare.sars@iki.fi");
- aboutData.addAuthor(ki18n("Arseniy Lartsev"),
- ki18n("contributor"),
- 0, 0);
+ aboutData.addAuthor(i18n("Arseniy Lartsev"),
+ i18n("contributor"));
- aboutData.addCredit(ki18n("Gilles Caulier"),
- ki18n("Importing libksane to extragear"),
- 0, 0);
+ aboutData.addCredit(i18n("Gilles Caulier"),
+ i18n("Importing libksane to extragear"));
- aboutData.addCredit(ki18n("Anne-Marie Mahfouf"),
- ki18n("Writing the user manual"),
- 0, 0);
+ aboutData.addCredit(i18n("Anne-Marie Mahfouf"),
+ i18n("Writing the user manual"));
- aboutData.addCredit(ki18n("Laurent Montel"),
- ki18n("Importing libksane to extragear"),
- 0, 0);
+ aboutData.addCredit(i18n("Laurent Montel"),
+ i18n("Importing libksane to extragear"));
- aboutData.addCredit(ki18n("Chusslove Illich"),
- ki18n("Help with translations"),
- 0, 0);
+ aboutData.addCredit(i18n("Chusslove Illich"),
+ i18n("Help with translations"));
- aboutData.addCredit(ki18n("Albert Astals Cid"),
- ki18n("Help with translations"),
- 0, 0);
+ aboutData.addCredit(i18n("Albert Astals Cid"),
+ i18n("Help with translations"));
aboutData.setProgramIconName("scanner");
- KCmdLineArgs::init(argc, argv, &aboutData);
-
- KCmdLineOptions options;
- options.add("d <device>", ki18n("Sane scanner device name."));
- KCmdLineArgs::addCmdLineOptions(options);
- KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
-
- QString device = args->getOption("d");
+ // FIXME KF5 is the command line parsing still working? (ported KCmdLineOptions to QCommandLineParser)
+ //KCmdLineArgs::init(argc, argv, &aboutData);
+ //KCmdLineOptions options;
+ //options.add("d <device>", ki18n("Sane scanner device name."));
+ //KCmdLineArgs::addCmdLineOptions(options);
+ //KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+ //QString device = args->getOption("d");
+ QString device; // FIXME KF5
KApplication app;
- Skanlite *skanlite = new Skanlite(device, 0);
+ Skanlite skanliteDialog(device, 0);
+ skanliteDialog.setAboutData(&aboutData);
- skanlite->show();
+ skanliteDialog.show();
QObject::connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
diff --git a/src/skanlite.cpp b/src/skanlite.cpp
index c8f6436..459e853 100644
--- a/src/skanlite.cpp
+++ b/src/skanlite.cpp
@@ -2,6 +2,7 @@
*
* Copyright (C) 2007-2012 by Kåre Särs <kare.sars@iki .fi>
* Copyright (C) 2009 by Arseniy Lartsev <receive-spam at yandex dot ru>
+* Copyright (C) 2014 by Gregor Mitsch: port to KDE5 frameworks
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -22,7 +23,6 @@
* ============================================================ */
#include "skanlite.h"
-#include "skanlite.moc"
#include "KSaneImageSaver.h"
#include "SaveLocation.h"
@@ -31,13 +31,13 @@
#include <QApplication>
#include <QScrollArea>
#include <QStringList>
+#include <QFileDialog>
+#include <QUrl>
#include <KAboutApplicationDialog>
#include <KAction>
#include <KComponentData>
#include <KDebug>
-#include <KFileDialog>
-#include <KUrl>
#include <KGlobal>
#include <KMessageBox>
#include <KStandardAction>
@@ -45,18 +45,20 @@
#include <kdeversion.h>
#include <kio/netaccess.h>
#include <KTemporaryFile>
+#include <kio/global.h>
#include <errno.h>
-Skanlite::Skanlite(const QString &device, QWidget *parent)
+Skanlite::Skanlite(const QString& device, QWidget* parent)
: KDialog(parent)
+ , m_aboutData(nullptr)
{
setAttribute(Qt::WA_DeleteOnClose);
setButtons(KDialog::Help | KDialog::User2 | KDialog::User1 | KDialog::Close);
setButtonText(KDialog::User1, i18n("Settings"));
- setButtonIcon(KDialog::User1, KIcon("configure"));
+ setButtonIcon(KDialog::User1, QIcon::fromTheme("configure"));
setButtonText(KDialog::User2, i18n("About"));
setHelp("index", "skanlite");
@@ -92,7 +94,7 @@ Skanlite::Skanlite(const QString &device, QWidget *parent)
QWidget *settingsWidget = new QWidget(m_settingsDialog);
m_settingsUi.setupUi(settingsWidget);
- m_settingsUi.revertOptions->setIcon(KIcon("edit-undo"));
+ m_settingsUi.revertOptions->setIcon(QIcon::fromTheme("edit-undo"));
m_saveLocation = new SaveLocation(this);
// add the supported image types
@@ -160,19 +162,12 @@ Skanlite::Skanlite(const QString &device, QWidget *parent)
m_showImgDialog = new KDialog(this);
m_showImgDialog->setButtons(KDialog::User1 | KDialog::Close);
m_showImgDialog->setButtonText(KDialog::User1, i18n("Save"));
- m_showImgDialog->setButtonIcon(KDialog::User1, KIcon("document-save"));
+ m_showImgDialog->setButtonIcon(KDialog::User1, QIcon::fromTheme("document-save"));
m_showImgDialog->setDefaultButton(KDialog::User1);
m_showImgDialog->resize(640, 480);
m_showImgDialog->setMainWidget(&m_imageViewer);
connect(m_showImgDialog, SIGNAL(user1Clicked()), this, SLOT(saveImage()));
-
- // prepare the save dialog
- m_saveDialog = new KFileDialog(m_settingsUi.saveDirLEdit->text(), QString(), this);
- m_saveDialog->setOperationMode(KFileDialog::Saving);
- m_saveDialog->setMode(KFile::File);
- m_saveDialog->setCaption(i18n("New Image File Name"));
-
// save the default sane options for later use
m_ksanew->getOptVals(m_defaultScanOpts);
@@ -184,6 +179,11 @@ Skanlite::Skanlite(const QString &device, QWidget *parent)
m_firstImage = true;
}
+void Skanlite::setAboutData(KAboutData* aboutData)
+{
+ m_aboutData = aboutData;
+}
+
//************************************************************
void Skanlite::closeEvent(QCloseEvent *event)
{
@@ -320,7 +320,7 @@ void Skanlite::saveImage()
{
// ask the first time if we are in "ask on first" mode
if ((m_settingsUi.saveModeCB->currentIndex() == SaveModeAskFirst) && m_firstImage) {
- if (m_saveLocation->exec() != KFileDialog::Accepted) return;
+ if (m_saveLocation->exec() != QFileDialog::Accepted) return;
m_firstImage = false;
}
@@ -341,7 +341,7 @@ void Skanlite::saveImage()
// find next available file name for name suggestion
- KUrl fileUrl;
+ QUrl fileUrl;
QString fname;
for (int i=fileNumber; i<=m_saveLocation->u_numStartFrom->maximum(); ++i) {
fname = QString("%1%2.%3")
@@ -349,7 +349,7 @@ void Skanlite::saveImage()
.arg(i, 4, 10, QChar('0'))
.arg(type);
- fileUrl = KUrl(QString("%1/%2").arg(dir).arg(fname));
+ fileUrl = QUrl(QString("%1/%2").arg(dir).arg(fname));
if (fileUrl.isLocalFile()) {
if (!QFileInfo(fileUrl.toLocalFile()).exists()) {
break;
@@ -363,14 +363,20 @@ void Skanlite::saveImage()
}
if (m_settingsUi.saveModeCB->currentIndex() == SaveModeManual) {
+ // prepare the save dialog
+ QFileDialog saveDialog(this, i18n("New Image File Name"), m_settingsUi.saveDirLEdit->text());
+ saveDialog.setAcceptMode(QFileDialog::AcceptSave);
+ saveDialog.setFileMode(QFileDialog::AnyFile);
+
// ask for a filename if requested.
- m_saveDialog->setSelection(fileUrl.url());
- m_saveDialog->setMimeFilter(filterList, "image/"+type);
+ saveDialog.selectFile(fileUrl.url());
+ //saveDialog.setMimeTypeFilters(filterList, "image/"+type); // FIXME KF5 API changed
- do {
- if (m_saveDialog->exec() != KFileDialog::Accepted) return;
+ do {
+ if (saveDialog.exec() != QFileDialog::Accepted) return;
- fileUrl = m_saveDialog->selectedUrl();
+ Q_ASSERT(!saveDialog.selectedUrls().isEmpty());
+ fileUrl = saveDialog.selectedUrls().first();
//kDebug() << "-----Save-----" << fname;
if (KIO::NetAccess::exists(fileUrl, true, this)) {
@@ -388,7 +394,7 @@ void Skanlite::saveImage()
else {
break;
}
- } while (1);
+ } while (true);
}
m_firstImage = false;
@@ -399,10 +405,10 @@ void Skanlite::saveImage()
quality = m_settingsUi.imgQuality->value();
}
- QFileInfo fileInfo(fileUrl.pathOrUrl());
+ QFileInfo fileInfo(fileUrl.path());
//kDebug() << "suffix" << fileInfo.suffix() << "localFile" << fileUrl.pathOrUrl();
- fname = fileUrl.pathOrUrl();
+ fname = fileUrl.path();
KTemporaryFile tmp;
if (!fileUrl.isLocalFile()) {
tmp.setSuffix('.'+fileInfo.suffix());
@@ -459,7 +465,7 @@ void Skanlite::saveImage()
if (m_settingsUi.saveModeCB->currentIndex() == SaveModeManual) {
// Save last used dir, prefix and suffix.
- m_saveLocation->u_saveDirLEdit->setText(fileUrl.upUrl().pathOrUrl());
+ m_saveLocation->u_saveDirLEdit->setText(KIO::upUrl(fileUrl).path());
m_saveLocation->u_imgFormat->setCurrentItem(fileInfo.suffix());
}
}
@@ -468,7 +474,7 @@ void Skanlite::saveImage()
//************************************************************
void Skanlite::getDir(void)
{
- QString dir = KFileDialog::getExistingDirectory(KUrl(m_settingsUi.saveDirLEdit->text()));
+ QString dir = QFileDialog::getExistingDirectory(this, QString(), m_settingsUi.saveDirLEdit->text());
if (!dir.isEmpty()) {
m_settingsUi.saveDirLEdit->setText(dir);
}
@@ -477,7 +483,7 @@ void Skanlite::getDir(void)
//************************************************************
void Skanlite::showAboutDialog(void)
{
- KAboutApplicationDialog(KGlobal::mainComponent().aboutData(), 0).exec();
+ KAboutApplicationDialog(*m_aboutData).exec();
}
//************************************************************
diff --git a/src/skanlite.h b/src/skanlite.h
index 9ada13f..16b455c 100644
--- a/src/skanlite.h
+++ b/src/skanlite.h
@@ -28,11 +28,13 @@
#include <KSane/ksane.h>
+#include <KDialog>
+
#include "ui_settings.h"
#include "ImageViewer.h"
-class KFileDialog;
class SaveLocation;
+class KAboutData;
using namespace KSaneIface;
@@ -41,7 +43,8 @@ class Skanlite : public KDialog
Q_OBJECT
public:
- explicit Skanlite(const QString& device, QWidget *parent = 0);
+ explicit Skanlite(const QString& device, QWidget* parent);
+ void setAboutData(KAboutData* aboutData);
private:
// Order of items in save mode combo-box
@@ -49,7 +52,7 @@ class Skanlite : public KDialog
SaveModeManual = 0,
SaveModeAskFirst = 1,
};
-
+
void readSettings();
void doSaveImage(bool askFilename = true);
void loadScannerOptions();
@@ -74,11 +77,11 @@ class Skanlite : public KDialog
void closeEvent(QCloseEvent *event);
private:
+ KAboutData* m_aboutData;
KSaneWidget *m_ksanew;
Ui::SkanliteSettings m_settingsUi;
KDialog *m_settingsDialog;
KDialog *m_showImgDialog;
- KFileDialog *m_saveDialog;
SaveLocation *m_saveLocation;
QString m_deviceName;
QMap<QString,QString> m_defaultScanOpts;
@@ -96,6 +99,5 @@ class Skanlite : public KDialog
bool m_firstImage;
};
-
#endif
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
new file mode 100644
index 0000000..0baa982
--- /dev/null
+++ b/tests/CMakeLists.txt
@@ -0,0 +1,15 @@
+find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Test)
+
+include(ECMMarkAsTest)
+
+macro(skanlite_executable_tests)
+ foreach(_testname ${ARGN})
+ add_executable(${_testname} ${_testname}.cpp)
+ target_link_libraries(${_testname} Qt5::Test KF5skanlite)
+ ecm_mark_as_test(${_testname})
+ endforeach(_testname)
+endmacro()
+
+#skanlite_executable_tests(
+# anothertest
+#)