diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f528ae9..645d4348 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,123 +1,124 @@ project(gwenview) # KDE Application Version, managed by release script set (KDE_APPLICATIONS_VERSION_MAJOR "15") set (KDE_APPLICATIONS_VERSION_MINOR "12") set (KDE_APPLICATIONS_VERSION_MICRO "3") set (KDE_APPLICATIONS_VERSION "${KDE_APPLICATIONS_VERSION_MAJOR}.${KDE_APPLICATIONS_VERSION_MINOR}.${KDE_APPLICATIONS_VERSION_MICRO}") set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ) cmake_minimum_required (VERSION 2.8.12 FATAL_ERROR) set (QT_MIN_VERSION "5.2.0") find_package(ECM 1.7.0 REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR}) include(KDEInstallDirs) include(KDECMakeSettings) include(KDECompilerSettings) include(ECMOptionalAddSubdirectory) include(ECMInstallIcons) include(ECMSetupVersion) include(ECMMarkNonGuiExecutable) include(ECMGenerateHeaders) include(ECMAddAppIcon) include(GenerateExportHeader) include(FeatureSummary) ## Generate header with version number ecm_setup_version(${KDE_APPLICATIONS_VERSION} VARIABLE_PREFIX GWENVIEW VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/lib/gwenview_version.h" ) ## CMake options set(GWENVIEW_SEMANTICINFO_BACKEND_NONE OFF) set(GWENVIEW_SEMANTICINFO_BACKEND_FAKE OFF) set(GWENVIEW_SEMANTICINFO_BACKEND_BALOO OFF) set(GWENVIEW_SEMANTICINFO_BACKEND "Baloo" CACHE STRING "Semantic info backend for Gwenview (Baloo/Fake/None)") # Init GWENVIEW_SEMANTICINFO_BACKEND_* vars if(GWENVIEW_SEMANTICINFO_BACKEND STREQUAL "None") set(GWENVIEW_SEMANTICINFO_BACKEND_NONE ON) elseif(GWENVIEW_SEMANTICINFO_BACKEND STREQUAL "Fake") set(GWENVIEW_SEMANTICINFO_BACKEND_FAKE ON) else() set(GWENVIEW_SEMANTICINFO_BACKEND_BALOO ON) endif() find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED Core Widgets Concurrent Svg OpenGL) find_package(Phonon4Qt5 4.6.60 NO_MODULE) include_directories(BEFORE ${PHONON_INCLUDES}) add_definitions(-DPHONON_LIB_SONAME=\"${PHONON_LIB_SONAME}\") find_package(KF5KIO 5.4 REQUIRED) find_package(KF5 REQUIRED COMPONENTS KDELibs4Support Activities + ItemModels ) ## Dependencies find_package(JPEG) set_package_properties(JPEG PROPERTIES URL "http://libjpeg.sourceforge.net/" DESCRIPTION "JPEG image manipulation support" TYPE REQUIRED) find_package(PNG) set_package_properties(PNG PROPERTIES URL "http://www.libpng.org" DESCRIPTION "PNG image manipulation support" TYPE REQUIRED) find_package(Exiv2) set_package_properties(EXIV2 PROPERTIES URL "http://www.exiv2.org" DESCRIPTION "image metadata support" TYPE REQUIRED) find_package(KF5Kipi) if (KF5Kipi_FOUND) set(KIPI_FOUND true) endif() # set_package_properties(Kipi PROPERTIES URL"http://www.kipi-plugins.org" DESCRIPTION "Provides various image manipulation and export features" TYPE OPTIONAL) find_package(LCMS2) set_package_properties(LCMS2 PROPERTIES URL "http://www.littlecms.com" DESCRIPTION "Color management engine" TYPE REQUIRED) if (GWENVIEW_SEMANTICINFO_BACKEND_BALOO) find_package(KF5Baloo 5.1.90) set_package_properties(KF5Baloo PROPERTIES URL "https://projects.kde.org/projects/kde/kdelibs/baloo" DESCRIPTION "Desktop-wide semantic information support" TYPE OPTIONAL) if (NOT KF5Baloo_FOUND) message (STATUS "You have selected Baloo for semantic backend, but required version was not found. Overriding the backend to None") unset(GWENVIEW_SEMANTICINFO_BACKEND_BALOO) set(GWENVIEW_SEMANTICINFO_BACKEND_NONE ON) endif () endif () find_package(KF5KDcraw) if (KF5KDcraw_FOUND) add_definitions(-DKDCRAW_FOUND) endif() #set_package_properties(KDCRAW_FOUND PROPERTIES URL "http://www.kde.org" DESCRIPTION "KDE Dcraw library" TYPE OPTIONAL) find_package(X11) if(X11_FOUND) find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED X11Extras) set(HAVE_X11 1) endif() configure_file(config-gwenview.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-gwenview.h) include_directories(${CMAKE_CURRENT_BINARY_DIR}) add_definitions(-DTRANSLATION_DOMAIN="gwenview") ## dirs to build add_subdirectory(lib) add_subdirectory(app) -# add_subdirectory(importer) +add_subdirectory(importer) add_subdirectory(part) add_subdirectory(tests) add_subdirectory(icons) add_subdirectory(images) add_subdirectory(cursors) add_subdirectory(color-schemes) add_subdirectory(doc) feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/importer/CMakeLists.txt b/importer/CMakeLists.txt index e75746e7..81e585c1 100644 --- a/importer/CMakeLists.txt +++ b/importer/CMakeLists.txt @@ -1,56 +1,60 @@ project(importer) include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_BINARY_DIR}/.. ${EXIV2_INCLUDE_DIR} ) set(importer_SRCS importerconfigdialog.cpp dialogpage.cpp documentdirfinder.cpp fileutils.cpp main.cpp importdialog.cpp importer.cpp progresspage.cpp filenameformater.cpp serializedurlmap.cpp thumbnailpage.cpp ) ki18n_wrap_ui(importer_SRCS dialogpage.ui importerconfigdialog.ui progresspage.ui thumbnailpage.ui ) -file(GLOB ICONS_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/../icons/hi*-apps-gwenview-importer.png") +file(GLOB ICONS_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/../icons/*-apps-gwenview.png") ecm_add_app_icon(importer_SRCS ICONS ${ICONS_SRCS}) kconfig_add_kcfg_files(importer_SRCS importerconfig.kcfgc ) +add_definitions(-DQT_NO_URL_CAST_FROM_STRING) + add_executable(gwenview_importer ${importer_SRCS}) target_link_libraries(gwenview_importer gwenviewlib KF5::KIOCore + KF5::ItemModels Qt5::Core ) target_link_libraries(gwenview_importer LINK_INTERFACE_LIBRARIES KF5::KIOCore + KF5::ItemModels Qt5::Core ) install(TARGETS gwenview_importer ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) install(FILES gwenview_importer.desktop gwenview_importer_camera.desktop DESTINATION ${KDE_INSTALL_DATADIR}/solid/actions/) diff --git a/importer/dialogpage.cpp b/importer/dialogpage.cpp index 5091cba2..f7a8fbc6 100644 --- a/importer/dialogpage.cpp +++ b/importer/dialogpage.cpp @@ -1,98 +1,98 @@ // vim: set tabstop=4 shiftwidth=4 expandtab: /* Gwenview: an image viewer Copyright 2009 Aurélien Gâteau This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA. */ // Self -#include "dialogpage.moc" +#include "dialogpage.h" // Qt #include #include #include #include // KDE #include // Local #include namespace Gwenview { struct DialogPagePrivate : public Ui_DialogPage { QVBoxLayout* mLayout; QList mButtons; QSignalMapper* mMapper; QEventLoop* mEventLoop; }; DialogPage::DialogPage(QWidget* parent) : QWidget(parent) , d(new DialogPagePrivate) { d->setupUi(this); d->mLayout = new QVBoxLayout(d->mButtonContainer); d->mMapper = new QSignalMapper(this); connect(d->mMapper, SIGNAL(mapped(int)), SLOT(slotMapped(int))); } DialogPage::~DialogPage() { delete d; } void DialogPage::removeButtons() { qDeleteAll(d->mButtons); d->mButtons.clear(); } void DialogPage::setText(const QString& text) { d->mLabel->setText(text); } int DialogPage::addButton(const KGuiItem& item) { int id = d->mButtons.size(); KPushButton* button = new KPushButton(item); button->setFixedHeight(button->sizeHint().height() * 2); connect(button, SIGNAL(clicked()), d->mMapper, SLOT(map())); d->mLayout->addWidget(button); d->mMapper->setMapping(button, id); d->mButtons << button; return id; } int DialogPage::exec() { QEventLoop loop; d->mEventLoop = &loop; return loop.exec(); } void DialogPage::slotMapped(int value) { d->mEventLoop->exit(value); } } // namespace diff --git a/importer/documentdirfinder.cpp b/importer/documentdirfinder.cpp index 0211aef0..8eaa63ae 100644 --- a/importer/documentdirfinder.cpp +++ b/importer/documentdirfinder.cpp @@ -1,114 +1,114 @@ // vim: set tabstop=4 shiftwidth=4 expandtab: /* Gwenview: an image viewer Copyright 2009 Aurélien Gâteau This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA. */ // Self -#include "documentdirfinder.moc" +#include "documentdirfinder.h" // Qt // KDE #include #include // Local #include namespace Gwenview { struct DocumentDirFinderPrivate { - KUrl mRootUrl; + QUrl mRootUrl; KDirLister* mDirLister; - KUrl mFoundDirUrl; + QUrl mFoundDirUrl; }; -DocumentDirFinder::DocumentDirFinder(const KUrl& rootUrl) +DocumentDirFinder::DocumentDirFinder(const QUrl& rootUrl) : d(new DocumentDirFinderPrivate) { d->mRootUrl = rootUrl; d->mDirLister = new KDirLister(this); - connect(d->mDirLister, SIGNAL(itemsAdded(KUrl,KFileItemList)), - SLOT(slotItemsAdded(KUrl,KFileItemList))); + connect(d->mDirLister, SIGNAL(itemsAdded(QUrl,KFileItemList)), + SLOT(slotItemsAdded(QUrl,KFileItemList))); connect(d->mDirLister, SIGNAL(completed()), SLOT(slotCompleted())); d->mDirLister->openUrl(rootUrl); } DocumentDirFinder::~DocumentDirFinder() { delete d; } void DocumentDirFinder::start() { d->mDirLister->openUrl(d->mRootUrl); } -void DocumentDirFinder::slotItemsAdded(const KUrl& dir, const KFileItemList& list) +void DocumentDirFinder::slotItemsAdded(const QUrl& dir, const KFileItemList& list) { Q_FOREACH(const KFileItem & item, list) { MimeTypeUtils::Kind kind = MimeTypeUtils::fileItemKind(item); switch (kind) { case MimeTypeUtils::KIND_DIR: case MimeTypeUtils::KIND_ARCHIVE: if (d->mFoundDirUrl.isValid()) { // This is the second dir we find, stop now finish(dir, MultipleDirsFound); return; } else { // First dir d->mFoundDirUrl = item.url(); } break; case MimeTypeUtils::KIND_RASTER_IMAGE: case MimeTypeUtils::KIND_SVG_IMAGE: case MimeTypeUtils::KIND_VIDEO: finish(dir, DocumentDirFound); return; case MimeTypeUtils::KIND_UNKNOWN: case MimeTypeUtils::KIND_FILE: break; } } } void DocumentDirFinder::slotCompleted() { if (d->mFoundDirUrl.isValid()) { - KUrl url = d->mFoundDirUrl; - d->mFoundDirUrl = KUrl(); + QUrl url = d->mFoundDirUrl; + d->mFoundDirUrl = QUrl(); d->mDirLister->openUrl(url); } else { finish(d->mRootUrl, NoDocumentFound); } } -void DocumentDirFinder::finish(const KUrl& url, DocumentDirFinder::Status status) +void DocumentDirFinder::finish(const QUrl& url, DocumentDirFinder::Status status) { disconnect(d->mDirLister, 0, this, 0); emit done(url, status); deleteLater(); } } // namespace diff --git a/importer/documentdirfinder.h b/importer/documentdirfinder.h index 4c01e0cb..05b96236 100644 --- a/importer/documentdirfinder.h +++ b/importer/documentdirfinder.h @@ -1,77 +1,77 @@ // vim: set tabstop=4 shiftwidth=4 expandtab: /* Gwenview: an image viewer Copyright 2009 Aurélien Gâteau This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA. */ #ifndef DOCUMENTDIRFINDER_H #define DOCUMENTDIRFINDER_H // Qt #include // KDE #include // Local namespace Gwenview { struct DocumentDirFinderPrivate; /** * This class is a worker which tries to find the document dir given a root * url. This is useful for digital camera cards, which often have a dir * hierarchy like this: * /DCIM * /FOOBAR * /PICT0001.JPG * /PICT0002.JPG * ... * /PICTnnnn.JPG */ class DocumentDirFinder : public QObject { Q_OBJECT public: enum Status { NoDocumentFound, DocumentDirFound, MultipleDirsFound }; - DocumentDirFinder(const KUrl& rootUrl); + DocumentDirFinder(const QUrl& rootUrl); ~DocumentDirFinder(); void start(); Q_SIGNALS: - void done(const KUrl&, DocumentDirFinder::Status); + void done(const QUrl&, DocumentDirFinder::Status); private Q_SLOTS: - void slotItemsAdded(const KUrl&, const KFileItemList&); + void slotItemsAdded(const QUrl&, const KFileItemList&); void slotCompleted(); private: DocumentDirFinderPrivate* const d; - void finish(const KUrl&, Status); + void finish(const QUrl&, Status); }; } // namespace #endif /* DOCUMENTDIRFINDER_H */ diff --git a/importer/filenameformater.cpp b/importer/filenameformater.cpp index 60805261..f9c33ec1 100644 --- a/importer/filenameformater.cpp +++ b/importer/filenameformater.cpp @@ -1,114 +1,114 @@ // vim: set tabstop=4 shiftwidth=4 expandtab: /* Gwenview: an image viewer Copyright 2009 Aurélien Gâteau This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA. */ // Self #include "filenameformater.h" // Qt +#include #include +#include // KDE -#include #include -#include // Local namespace Gwenview { typedef QHash Dict; struct FileNameFormaterPrivate { QString mFormat; }; FileNameFormater::FileNameFormater(const QString& format) : d(new FileNameFormaterPrivate) { d->mFormat = format; } FileNameFormater::~FileNameFormater() { delete d; } -QString FileNameFormater::format(const KUrl& url, const KDateTime& dateTime) +QString FileNameFormater::format(const QUrl& url, const QDateTime& dateTime) { QFileInfo info(url.fileName()); // Keep in sync with helpMap() Dict dict; - dict["date"] = dateTime.toString("%Y-%m-%d"); - dict["time"] = dateTime.toString("%H-%M-%S"); + dict["date"] = dateTime.toString("yyyy-MM-dd"); + dict["time"] = dateTime.toString("HH-mm-ss"); dict["ext"] = info.suffix(); dict["ext.lower"] = info.suffix().toLower(); dict["name"] = info.completeBaseName(); dict["name.lower"] = info.completeBaseName().toLower(); QString name; int length = d->mFormat.length(); for (int pos = 0; pos < length; ++pos) { QChar ch = d->mFormat[pos]; if (ch == '{') { if (pos == length - 1) { // We are at the end, ignore this break; } if (d->mFormat[pos + 1] == '{') { // This is an escaped '{', skip one name += '{'; ++pos; continue; } int end = d->mFormat.indexOf('}', pos + 1); if (end == -1) { // No '}' found, stop here return name; } // Replace keyword with its value QString keyword = d->mFormat.mid(pos + 1, end - pos - 1); name += dict.value(keyword); pos = end; } else { name += ch; } } return name; } FileNameFormater::HelpMap FileNameFormater::helpMap() { // Keep in sync with dict in format() static HelpMap map; if (map.isEmpty()) { map["date"] = i18n("Shooting date"); map["time"] = i18n("Shooting time"); map["ext"] = i18n("Original extension"); map["ext.lower"] = i18n("Original extension, in lower case"); map["name"] = i18n("Original filename"); map["name.lower"] = i18n("Original filename, in lower case"); } return map; } } // namespace diff --git a/importer/filenameformater.h b/importer/filenameformater.h index 97205d74..f16409d3 100644 --- a/importer/filenameformater.h +++ b/importer/filenameformater.h @@ -1,66 +1,65 @@ // vim: set tabstop=4 shiftwidth=4 expandtab: /* Gwenview: an image viewer Copyright 2009 Aurélien Gâteau This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA. */ #ifndef FILENAMEFORMATER_H #define FILENAMEFORMATER_H // Qt #include // KDE // Local +class QDateTime; class QString; - -class KDateTime; -class KUrl; +class QUrl; namespace Gwenview { struct FileNameFormaterPrivate; class FileNameFormater { public: typedef QMap HelpMap; FileNameFormater(const QString& format); ~FileNameFormater(); /** * Given an url and its dateTime, returns a filename according to the * format passed to the constructor */ - QString format(const KUrl& url, const KDateTime& dateTime); + QString format(const QUrl& url, const QDateTime& dateTime); /** * Returns a map whose keys are the available keywords and values are the * keyword help */ static HelpMap helpMap(); private: FileNameFormaterPrivate* const d; }; } // namespace #endif /* FILENAMEFORMATER_H */ diff --git a/importer/fileutils.cpp b/importer/fileutils.cpp index 258c5920..35a22e0b 100644 --- a/importer/fileutils.cpp +++ b/importer/fileutils.cpp @@ -1,142 +1,145 @@ // vim: set tabstop=4 shiftwidth=4 expandtab: /* Gwenview: an image viewer Copyright 2009 Aurélien Gâteau This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA. */ // Self #include "fileutils.h" // Qt #include #include +#include // KDE #include #include #include #include #include #include #include -#include // libc #include #include #include namespace Gwenview { namespace FileUtils { -bool contentsAreIdentical(const KUrl& url1, const KUrl& url2, QWidget* authWindow) +bool contentsAreIdentical(const QUrl& url1, const QUrl& url2, QWidget* authWindow) { // FIXME: Support remote urls QFile file1(KIO::NetAccess::mostLocalUrl(url1, authWindow).toLocalFile()); if (!file1.open(QIODevice::ReadOnly)) { // Can't read url1, assume it's different from url2 qWarning() << "Can't read" << url1; return false; } QFile file2(KIO::NetAccess::mostLocalUrl(url2, authWindow).toLocalFile()); if (!file2.open(QIODevice::ReadOnly)) { // Can't read url2, assume it's different from url1 qWarning() << "Can't read" << url2; return false; } const int CHUNK_SIZE = 4096; while (!file1.atEnd() && !file2.atEnd()) { QByteArray url1Array = file1.read(CHUNK_SIZE); QByteArray url2Array = file2.read(CHUNK_SIZE); if (url1Array != url2Array) { return false; } } if (file1.atEnd() && file2.atEnd()) { return true; } else { qWarning() << "One file ended before the other"; return false; } } -RenameResult rename(const KUrl& src, const KUrl& dst_, QWidget* authWindow) +RenameResult rename(const QUrl& src, const QUrl& dst_, QWidget* authWindow) { - KUrl dst = dst_; + QUrl dst = dst_; RenameResult result = RenamedOK; int count = 1; QFileInfo fileInfo(dst.fileName()); QString prefix = fileInfo.completeBaseName() + '_'; QString suffix = '.' + fileInfo.suffix(); // Get src size KIO::UDSEntry udsEntry; KIO::NetAccess::stat(src, udsEntry, authWindow); KFileItem item(udsEntry, src, true /* delayedMimeTypes */); KIO::filesize_t srcSize = item.size(); // Find unique name while (KIO::NetAccess::stat(dst, udsEntry, authWindow)) { // File exists. If it's not the same, try to create a new name item = KFileItem(udsEntry, dst, true /* delayedMimeTypes */); KIO::filesize_t dstSize = item.size(); if (srcSize == dstSize && contentsAreIdentical(src, dst, authWindow)) { // Already imported, skip it KIO::Job* job = KIO::file_delete(src, KIO::HideProgressInfo); + // FIXME KF5 + /* if (job->ui()) { job->ui()->setWindow(authWindow); } + */ return Skipped; } result = RenamedUnderNewName; - dst.setFileName(prefix + QString::number(count) + suffix); + dst.setPath(dst.path() + '/' + prefix + QString::number(count) + suffix); ++count; } // Rename KIO::Job* job = KIO::rename(src, dst, KIO::HideProgressInfo); if (!KIO::NetAccess::synchronousRun(job, authWindow)) { result = RenameFailed; } return result; } QString createTempDir(const QString& baseDir, const QString& prefix, QString* errorMessage) { Q_ASSERT(errorMessage); QByteArray name = QFile::encodeName(baseDir + '/' + prefix + "XXXXXX"); if (!mkdtemp(name.data())) { // Failure *errorMessage = QString::fromLocal8Bit(::strerror(errno)); return QString(); } return QFile::decodeName(name + '/'); } } // namespace } // namespace diff --git a/importer/fileutils.h b/importer/fileutils.h index e81c1db8..db10f56e 100644 --- a/importer/fileutils.h +++ b/importer/fileutils.h @@ -1,63 +1,63 @@ // vim: set tabstop=4 shiftwidth=4 expandtab: /* Gwenview: an image viewer Copyright 2009 Aurélien Gâteau This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA. */ #ifndef FILEUTILS_H #define FILEUTILS_H class QString; class QWidget; -class KUrl; +class QUrl; namespace Gwenview { namespace FileUtils { enum RenameResult { RenamedOK, /** Renamed without problem */ RenamedUnderNewName, /** Destination already existed, so rename() added a suffix to make the name unique */ Skipped, /** Destination already existed and contained the same data as source, so rename() just removed the source */ RenameFailed /** Rename failed */ }; /** * Compare content of two urls, returns whether they are the same */ -bool contentsAreIdentical(const KUrl& url1, const KUrl& url2, QWidget* authWindow = 0); +bool contentsAreIdentical(const QUrl& url1, const QUrl& url2, QWidget* authWindow = 0); /** * Rename src to dst, returns RenameResult */ -RenameResult rename(const KUrl& src, const KUrl& dst, QWidget* authWindow = 0); +RenameResult rename(const QUrl& src, const QUrl& dst, QWidget* authWindow = 0); /** * Create a temp dir in baseDir, starting with prefix. If successful returns * the created dir otherwise returns an empty string and writes the error message * in errorMessage. * * errorMessage must be a valid pointer. */ QString createTempDir(const QString& baseDir, const QString& prefix, QString* errorMessage); } // namespace } // namespace #endif /* FILEUTILS_H */ diff --git a/importer/importdialog.cpp b/importer/importdialog.cpp index 2a4d4683..7c85f519 100644 --- a/importer/importdialog.cpp +++ b/importer/importdialog.cpp @@ -1,269 +1,269 @@ // vim: set tabstop=4 shiftwidth=4 expandtab: /* Gwenview: an image viewer Copyright 2009 Aurélien Gâteau This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA. */ // Self -#include "importdialog.moc" +#include "importdialog.h" // Qt #include #include #include // KDE #include #include #include #include #include #include #include #include #include #include #include #include // Local #include "dialogpage.h" #include "importer.h" #include "importerconfig.h" #include "progresspage.h" #include "thumbnailpage.h" namespace Gwenview { class ImportDialogPrivate { public: ImportDialog* q; QStackedWidget* mCentralWidget; ThumbnailPage* mThumbnailPage; ProgressPage* mProgressPage; DialogPage* mDialogPage; Importer* mImporter; void deleteImportedUrls() { - KUrl::List importedUrls = mImporter->importedUrlList(); - KUrl::List skippedUrls = mImporter->skippedUrlList(); + QList importedUrls = mImporter->importedUrlList(); + QList skippedUrls = mImporter->skippedUrlList(); int importedCount = importedUrls.count(); int skippedCount = skippedUrls.count(); if (importedCount == 0 && skippedCount == 0) { return; } QStringList message; message << i18np( "One document has been imported.", "%1 documents have been imported.", importedCount); if (skippedCount > 0) { message << i18np( "One document has been skipped because it had already been imported.", "%1 documents have been skipped because they had already been imported.", skippedCount); } if (mImporter->renamedCount() > 0) { message[0].append("*"); message << "* " + i18np( "One of them has been renamed because another document with the same name had already been imported.", "%1 of them have been renamed because other documents with the same name had already been imported.", mImporter->renamedCount()) + ""; } message << QString(); if (skippedCount == 0) { message << i18np( "Delete the imported document from the device?", "Delete the %1 imported documents from the device?", importedCount); } else if (importedCount == 0) { message << i18np( "Delete the skipped document from the device?", "Delete the %1 skipped documents from the device?", skippedCount); } else { message << i18ncp( "Singular sentence is actually never used.", "Delete the imported or skipped document from the device?", "Delete the %1 imported and skipped documents from the device?", importedCount + skippedCount); } int answer = KMessageBox::questionYesNo(mCentralWidget, "" + message.join("
") + "
", i18nc("@title:window", "Import Finished"), KStandardGuiItem::del(), KGuiItem(i18n("Keep")) ); if (answer != KMessageBox::Yes) { return; } - KUrl::List urls = importedUrls + skippedUrls; + QList urls = importedUrls + skippedUrls; while (true) { KIO::Job* job = KIO::del(urls); if (KIO::NetAccess::synchronousRun(job, q)) { break; } // Deleting failed int answer = KMessageBox::warningYesNo(mCentralWidget, i18np("Failed to delete the document:\n%2", "Failed to delete documents:\n%2", urls.count(), job->errorString()), QString(), KGuiItem(i18n("Retry")), KGuiItem(i18n("Ignore")) ); if (answer != KMessageBox::Yes) { // Ignore break; } } } void startGwenview() { - KService::Ptr service = KService::serviceByDesktopName("gwenview"); + KService::Ptr service = KService::serviceByDesktopName("org.kde.gwenview"); if (!service) { qCritical() << "Could not find gwenview"; } else { - KRun::run(*service, KUrl::List() << mThumbnailPage->destinationUrl(), 0 /* window */); + KRun::run(*service, {mThumbnailPage->destinationUrl()}, 0 /* window */); } } void showWhatNext() { mCentralWidget->setCurrentWidget(mDialogPage); mDialogPage->setText(i18n("What do you want to do now?")); mDialogPage->removeButtons(); int gwenview = mDialogPage->addButton(KGuiItem(i18n("View Imported Documents with Gwenview"), "gwenview")); int importMore = mDialogPage->addButton(KGuiItem(i18n("Import more Documents"))); mDialogPage->addButton(KGuiItem(i18n("Quit"), "dialog-cancel")); int answer = mDialogPage->exec(); if (answer == gwenview) { startGwenview(); qApp->quit(); } else if (answer == importMore) { mCentralWidget->setCurrentWidget(mThumbnailPage); } else { /* quit */ qApp->quit(); } } }; ImportDialog::ImportDialog() : d(new ImportDialogPrivate) { d->q = this; d->mImporter = new Importer(this); connect(d->mImporter, SIGNAL(error(QString)), SLOT(showImportError(QString))); d->mThumbnailPage = new ThumbnailPage; - KUrl url = ImporterConfig::destinationUrl(); + QUrl url = ImporterConfig::destinationUrl(); if (!url.isValid()) { url = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)); int year = QDate::currentDate().year(); - url.addPath(QString::number(year)); + url.setPath(url.path() + '/' + QString::number(year)); } d->mThumbnailPage->setDestinationUrl(url); d->mProgressPage = new ProgressPage(d->mImporter); d->mDialogPage = new DialogPage; d->mCentralWidget = new QStackedWidget; setCentralWidget(d->mCentralWidget); d->mCentralWidget->addWidget(d->mThumbnailPage); d->mCentralWidget->addWidget(d->mProgressPage); d->mCentralWidget->addWidget(d->mDialogPage); connect(d->mThumbnailPage, SIGNAL(importRequested()), SLOT(startImport())); connect(d->mThumbnailPage, SIGNAL(rejected()), SLOT(close())); connect(d->mImporter, SIGNAL(importFinished()), SLOT(slotImportFinished())); d->mCentralWidget->setCurrentWidget(d->mThumbnailPage); - setWindowIcon(KIcon("gwenview")); + setWindowIcon(QIcon::fromTheme("gwenview")); setAutoSaveSettings(); } ImportDialog::~ImportDialog() { delete d; } QSize ImportDialog::sizeHint() const { return QSize(700, 500); } -void ImportDialog::setSourceUrl(const KUrl& url, const QString& deviceUdi) +void ImportDialog::setSourceUrl(const QUrl& url, const QString& deviceUdi) { QString name, iconName; if (deviceUdi.isEmpty()) { - name = url.pathOrUrl(); - iconName = KProtocolInfo::icon(url.protocol()); + name = url.url(QUrl::PreferLocalFile); + iconName = KProtocolInfo::icon(url.scheme()); if (iconName.isEmpty()) { iconName = "folder"; } } else { Solid::Device device(deviceUdi); name = device.vendor() + " " + device.product(); iconName = device.icon(); } d->mThumbnailPage->setSourceUrl(url, iconName, name); } void ImportDialog::startImport() { - KUrl url = d->mThumbnailPage->destinationUrl(); + QUrl url = d->mThumbnailPage->destinationUrl(); ImporterConfig::setDestinationUrl(url); ImporterConfig::self()->save(); d->mCentralWidget->setCurrentWidget(d->mProgressPage); d->mImporter->setAutoRenameFormat( ImporterConfig::autoRename() ? ImporterConfig::autoRenameFormat() : QString()); d->mImporter->start(d->mThumbnailPage->urlList(), url); } void ImportDialog::slotImportFinished() { d->deleteImportedUrls(); d->showWhatNext(); } void ImportDialog::showImportError(const QString& message) { KMessageBox::sorry(this, message); d->mCentralWidget->setCurrentWidget(d->mThumbnailPage); } } // namespace diff --git a/importer/importdialog.h b/importer/importdialog.h index f8f56d34..4abe82fc 100644 --- a/importer/importdialog.h +++ b/importer/importdialog.h @@ -1,59 +1,59 @@ // vim: set tabstop=4 shiftwidth=4 expandtab: /* Gwenview: an image viewer Copyright 2009 Aurélien Gâteau This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA. */ #ifndef IMPORTDIALOG_H #define IMPORTDIALOG_H // Qt +#include // KDE -#include #include // Local namespace Gwenview { class ImportDialogPrivate; class ImportDialog : public KMainWindow { Q_OBJECT public: ImportDialog(); ~ImportDialog(); virtual QSize sizeHint() const; public Q_SLOTS: - void setSourceUrl(const KUrl&, const QString& deviceUdi); + void setSourceUrl(const QUrl&, const QString& deviceUdi); private Q_SLOTS: void startImport(); void slotImportFinished(); void showImportError(const QString&); private: ImportDialogPrivate* const d; }; } // namespace #endif /* IMPORTDIALOG_H */ diff --git a/importer/importer.cpp b/importer/importer.cpp index 25bb4ee2..b6063603 100644 --- a/importer/importer.cpp +++ b/importer/importer.cpp @@ -1,247 +1,251 @@ // vim: set tabstop=4 shiftwidth=4 expandtab: /* Gwenview: an image viewer Copyright 2009 Aurélien Gâteau This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA. */ // Self -#include "importer.moc" +#include "importer.h" // Qt +#include +#include +#include // KDE -#include -#include #include #include -#include #include #include #include #include #include #include // stdc++ #include // Local #include #include #include #include namespace Gwenview { struct ImporterPrivate { Importer* q; QWidget* mAuthWindow; std::auto_ptr mFileNameFormater; - KUrl mTempImportDir; + QUrl mTempImportDirUrl; /* @defgroup reset Should be reset in start() * @{ */ - KUrl::List mUrlList; - KUrl::List mImportedUrlList; - KUrl::List mSkippedUrlList; + QList mUrlList; + QList mImportedUrlList; + QList mSkippedUrlList; int mRenamedCount; int mProgress; int mJobProgress; /* @} */ - KUrl mCurrentUrl; + QUrl mCurrentUrl; void emitError(const QString& message) { QMetaObject::invokeMethod(q, "error", Q_ARG(QString, message)); } - bool createImportDir(const KUrl url) + bool createImportDir(const QUrl url) { Q_ASSERT(url.isLocalFile()); // FIXME: Support remote urls if (!QDir().mkpath(url.toLocalFile())) { emitError(i18n("Could not create destination folder.")); return false; } QString message; - mTempImportDir = FileUtils::createTempDir(url.toLocalFile(), ".gwenview_importer-", &message); - if (mTempImportDir.isEmpty()) { + QString dir = FileUtils::createTempDir(url.toLocalFile(), ".gwenview_importer-", &message); + mTempImportDirUrl = QUrl::fromLocalFile(dir); + if (mTempImportDirUrl.isEmpty()) { emitError(i18n("Could not create temporary upload folder:\n%1", message)); return false; } return true; } void importNext() { if (mUrlList.empty()) { q->finalizeImport(); return; } mCurrentUrl = mUrlList.takeFirst(); - KUrl dst = mTempImportDir; - dst.addPath(mCurrentUrl.fileName()); + QUrl dst = mTempImportDirUrl; + dst.setPath(dst.path() + '/' + mCurrentUrl.fileName()); KIO::Job* job = KIO::copy(mCurrentUrl, dst, KIO::HideProgressInfo); + /* KF5 FIXME if (job->ui()) { job->ui()->setWindow(mAuthWindow); } + */ QObject::connect(job, SIGNAL(result(KJob*)), q, SLOT(slotCopyDone(KJob*))); QObject::connect(job, SIGNAL(percent(KJob*,ulong)), q, SLOT(slotPercent(KJob*,ulong))); } - void renameImportedUrl(const KUrl& src) + void renameImportedUrl(const QUrl& src) { - KUrl dst = src; - dst.cd(".."); + QUrl dst = src.resolved(QUrl("..")); QString fileName; if (mFileNameFormater.get()) { KFileItem item(KFileItem::Unknown, KFileItem::Unknown, src, true /* delayedMimeTypes */); // Get the document time, but do not cache the result because the // 'src' url is temporary: if we import "foo/image.jpg" and // "bar/image.jpg", both images will be temporarily saved in the // 'src' url. - KDateTime dateTime = TimeUtils::dateTimeForFileItem(item, TimeUtils::SkipCache); + QDateTime dateTime = TimeUtils::dateTimeForFileItem(item, TimeUtils::SkipCache); fileName = mFileNameFormater->format(src, dateTime); } else { fileName = src.fileName(); } - dst.setFileName(fileName); + dst.setPath(dst.path() + '/' + fileName); FileUtils::RenameResult result = FileUtils::rename(src, dst, mAuthWindow); switch (result) { case FileUtils::RenamedOK: mImportedUrlList << mCurrentUrl; break; case FileUtils::RenamedUnderNewName: mRenamedCount++; mImportedUrlList << mCurrentUrl; break; case FileUtils::Skipped: mSkippedUrlList << mCurrentUrl; break; case FileUtils::RenameFailed: qWarning() << "Rename failed for" << mCurrentUrl; } q->advance(); importNext(); } }; Importer::Importer(QWidget* parent) : QObject(parent) , d(new ImporterPrivate) { d->q = this; d->mAuthWindow = parent; } Importer::~Importer() { delete d; } void Importer::setAutoRenameFormat(const QString& format) { if (format.isEmpty()) { d->mFileNameFormater.reset(0); } else { d->mFileNameFormater.reset(new FileNameFormater(format)); } } -void Importer::start(const KUrl::List& list, const KUrl& destination) +void Importer::start(const QList& list, const QUrl& destination) { d->mUrlList = list; d->mImportedUrlList.clear(); d->mSkippedUrlList.clear(); d->mRenamedCount = 0; d->mProgress = 0; d->mJobProgress = 0; emitProgressChanged(); maximumChanged(d->mUrlList.count() * 100); if (!d->createImportDir(destination)) { qWarning() << "Could not create import dir"; return; } d->importNext(); } void Importer::slotCopyDone(KJob* _job) { KIO::CopyJob* job = static_cast(_job); - KUrl url = job->destUrl(); + QUrl url = job->destUrl(); if (job->error()) { qWarning() << "FIXME: What do we do with failed urls?"; advance(); d->importNext(); return; } d->renameImportedUrl(url); } void Importer::finalizeImport() { - KIO::Job* job = KIO::del(d->mTempImportDir, KIO::HideProgressInfo); + KIO::Job* job = KIO::del(d->mTempImportDirUrl, KIO::HideProgressInfo); + /* KF5 FIXME if (job->ui()) { job->ui()->setWindow(d->mAuthWindow); } + */ importFinished(); } void Importer::advance() { ++d->mProgress; d->mJobProgress = 0; emitProgressChanged(); } void Importer::slotPercent(KJob*, unsigned long percent) { d->mJobProgress = percent; emitProgressChanged(); } void Importer::emitProgressChanged() { progressChanged(d->mProgress * 100 + d->mJobProgress); } -KUrl::List Importer::importedUrlList() const +QList Importer::importedUrlList() const { return d->mImportedUrlList; } -KUrl::List Importer::skippedUrlList() const +QList Importer::skippedUrlList() const { return d->mSkippedUrlList; } int Importer::renamedCount() const { return d->mRenamedCount; } } // namespace diff --git a/importer/importer.h b/importer/importer.h index 0f175da7..3efa2826 100644 --- a/importer/importer.h +++ b/importer/importer.h @@ -1,92 +1,92 @@ // vim: set tabstop=4 shiftwidth=4 expandtab: /* Gwenview: an image viewer Copyright 2009 Aurélien Gâteau This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA. */ #ifndef IMPORTER_H #define IMPORTER_H // Qt #include +#include // KDE -#include // Local class KJob; namespace Gwenview { struct ImporterPrivate; class Importer : public QObject { Q_OBJECT public: Importer(QWidget* authWindow); ~Importer(); /** * Defines the auto-rename format applied to imported documents * Set to QString() to reset */ void setAutoRenameFormat(const QString&); - void start(const KUrl::List& list, const KUrl& destUrl); + void start(const QList& list, const QUrl& destUrl); - KUrl::List importedUrlList() const; + QList importedUrlList() const; /** * Documents which have been skipped during import */ - KUrl::List skippedUrlList() const; + QList skippedUrlList() const; /** * How many documents have been renamed during import */ int renamedCount() const; Q_SIGNALS: void importFinished(); void progressChanged(int); void maximumChanged(int); /** * An error has occurred and caused the whole process to stop without * importing anything */ void error(const QString& message); private Q_SLOTS: void slotCopyDone(KJob*); void slotPercent(KJob*, unsigned long); void emitProgressChanged(); private: friend struct ImporterPrivate; ImporterPrivate* const d; void advance(); void finalizeImport(); }; } // namespace #endif /* IMPORTER_H */ diff --git a/importer/importerconfigdialog.cpp b/importer/importerconfigdialog.cpp index 87619f1f..73859775 100644 --- a/importer/importerconfigdialog.cpp +++ b/importer/importerconfigdialog.cpp @@ -1,102 +1,103 @@ // vim: set tabstop=4 shiftwidth=4 expandtab: /* Gwenview: an image viewer Copyright 2009 Aurélien Gâteau This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA. */ // Self -#include "importerconfigdialog.moc" +#include "importerconfigdialog.h" // Qt #include // KDE #include // Local #include "filenameformater.h" #include "importerconfig.h" #include "ui_importerconfigdialog.h" namespace Gwenview { static const QString PREVIEW_FILENAME = "PICT0012.JPG"; -static const KDateTime PREVIEW_DATETIME = KDateTime(QDate(2009, 10, 25), QTime(17, 51, 18)); +static const QDateTime PREVIEW_DATETIME = QDateTime(QDate(2009, 10, 25), QTime(17, 51, 18)); struct ImporterConfigDialogPrivate : public Ui_ImporterConfigDialog { ImporterConfigDialog* q; void setupHelpText() { QString helpText = "
    "; FileNameFormater::HelpMap map = FileNameFormater::helpMap(); FileNameFormater::HelpMap::ConstIterator it = map.constBegin(), end = map.constEnd(); for (; it != end; ++it) { QString keyword = '{' + it.key() + '}'; QString explanation = it.value().toHtmlEscaped(); QString link = QString("%1").arg(keyword); helpText += "
  • " + i18nc("%1 is the importer keyword, %2 is keyword explanation", "%1: %2", link, explanation) + "
  • "; } helpText += "
"; mRenameFormatHelpLabel->setText(helpText); QObject::connect(mRenameFormatHelpLabel, SIGNAL(linkActivated(QString)), q, SLOT(slotHelpLinkActivated(QString))); } }; ImporterConfigDialog::ImporterConfigDialog(QWidget* parent) : KConfigDialog(parent, "Importer Settings", ImporterConfig::self()) , d(new ImporterConfigDialogPrivate) { d->q = this; QWidget* widget = new QWidget; d->setupUi(widget); setFaceType(KPageDialog::Plain); + /* KF5 FIXME // Hide help button until there is actual documentation to show showButton(KDialog::Help, false); - showButtonSeparator(true); + */ addPage(widget, QString()); connect(d->kcfg_AutoRenameFormat, SIGNAL(textChanged(QString)), SLOT(updatePreview())); d->setupHelpText(); updatePreview(); } ImporterConfigDialog::~ImporterConfigDialog() { delete d; } void ImporterConfigDialog::slotHelpLinkActivated(const QString& keyword) { d->kcfg_AutoRenameFormat->insert(keyword); } void ImporterConfigDialog::updatePreview() { FileNameFormater formater(d->kcfg_AutoRenameFormat->text()); d->mPreviewOutputLabel->setText(formater.format(QUrl::fromLocalFile('/' + PREVIEW_FILENAME), PREVIEW_DATETIME)); } } // namespace diff --git a/importer/main.cpp b/importer/main.cpp index 3f5e5c10..85dbdc21 100644 --- a/importer/main.cpp +++ b/importer/main.cpp @@ -1,74 +1,77 @@ /* Gwenview: an image viewer Copyright 2000-2009 Aurélien Gâteau This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ // Qt +#include +#include +#include +#include #include +#include // KDE #include -#include #include -#include #include -#include // Local #include #include #include "importdialog.h" int main(int argc, char *argv[]) { QScopedPointer aboutData( Gwenview::createAboutData( - "gwenview_importer", /* appname */ - "gwenview", /* catalogName */ - ki18n("Gwenview Importer") /* programName */ + QStringLiteral("org.kde.gwenview"), /* component name */ + i18n("Gwenview Importer") /* programName */ )); - aboutData->setShortDescription(ki18n("Photo Importer")); - - KCmdLineArgs::init(argc, argv, aboutData.data()); + aboutData->setShortDescription(i18n("Photo Importer")); - KCmdLineOptions options; - options.add("+folder", ki18n("Source folder")); - options.add("udi ", ki18n("Device UDI")); - KCmdLineArgs::addCmdLineOptions(options); + QApplication app(argc, argv); + KAboutData::setApplicationData(*aboutData); - KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); - KApplication app; + QCommandLineParser parser; + aboutData.data()->setupCommandLine(&parser); + parser.addOption(QCommandLineOption({QStringLiteral("udi")}, i18n("Device UDI"))); + parser.addHelpOption(); + parser.addVersionOption(); + parser.addPositionalArgument("folder", i18n("Source folder")); + parser.process(app); + aboutData.data()->processCommandLine(&parser); - if (args->count() != 1) { - KCmdLineArgs::usageError("Missing required source folder argument."); // FIXME 2.11 Add i18n() call + if (parser.positionalArguments().count() != 1) { + KCmdLineArgs::usageError(i18n("Missing required source folder argument.")); return 1; } - KUrl url = args->url(0); + QString urlString = parser.positionalArguments().first(); + QUrl url = QUrl::fromUserInput(urlString, QDir::currentPath(), QUrl::AssumeLocalFile); if (!url.isValid()) { - qCritical() << "Invalid source folder."; // FIXME 2.11 Add i18n() call + qCritical() << i18n("Invalid source folder."); return 1; } - QString deviceUdi = args->isSet("udi") ? args->getOption("udi") : QString(); - args->clear(); + QString deviceUdi = parser.isSet("udi") ? parser.value("udi") : QString(); Gwenview::ImageFormats::registerPlugins(); Gwenview::ImportDialog* dialog = new Gwenview::ImportDialog(); dialog->show(); - QMetaObject::invokeMethod(dialog, "setSourceUrl", Qt::QueuedConnection, Q_ARG(KUrl, url), Q_ARG(QString, deviceUdi)); + QMetaObject::invokeMethod(dialog, "setSourceUrl", Qt::QueuedConnection, Q_ARG(QUrl, url), Q_ARG(QString, deviceUdi)); return app.exec(); } diff --git a/importer/progresspage.h b/importer/progresspage.h index bd1856ad..1a5e84b5 100644 --- a/importer/progresspage.h +++ b/importer/progresspage.h @@ -1,51 +1,50 @@ // vim: set tabstop=4 shiftwidth=4 expandtab: /* Gwenview: an image viewer Copyright 2009 Aurélien Gâteau This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA. */ #ifndef PROGRESSPAGE_H #define PROGRESSPAGE_H // Qt #include // KDE -#include // Local namespace Gwenview { class Importer; struct ProgressPagePrivate; class ProgressPage : public QWidget { Q_OBJECT public: ProgressPage(Importer*); ~ProgressPage(); private: ProgressPagePrivate* const d; }; } // namespace #endif /* PROGRESSPAGE_H */ diff --git a/importer/serializedurlmap.cpp b/importer/serializedurlmap.cpp index 172761b4..4127071d 100644 --- a/importer/serializedurlmap.cpp +++ b/importer/serializedurlmap.cpp @@ -1,110 +1,110 @@ // vim: set tabstop=4 shiftwidth=4 expandtab: /* Gwenview: an image viewer Copyright 2012 Aurélien Gâteau This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA. */ // Self #include // Local // KDE #include -#include // Qt +#include namespace Gwenview { static const char* KEY_SUFFIX = "key"; static const char* VALUE_SUFFIX = "value"; -static KUrl stripPass(const KUrl &url_) +static QUrl stripPass(const QUrl &url_) { - KUrl url = url_; - url.setPass(QString()); + QUrl url = url_; + url.setPassword(QString()); return url; } struct SerializedUrlMapPrivate { KConfigGroup mGroup; - QMap mMap; + QMap mMap; void read() { mMap.clear(); for (int idx=0;; ++idx) { QString idxString = QString::number(idx); QString key = idxString + QLatin1String(KEY_SUFFIX); if (!mGroup.hasKey(key)) { break; } - QString keyUrl = mGroup.readEntry(key); - QString valueUrl = mGroup.readEntry(idxString + QLatin1String(VALUE_SUFFIX)); - mMap.insert(keyUrl, valueUrl); + QVariant keyUrl = mGroup.readEntry(key, QVariant()); + QVariant valueUrl = mGroup.readEntry(idxString + QLatin1String(VALUE_SUFFIX), QVariant()); + mMap.insert(keyUrl.toUrl(), valueUrl.toUrl()); } } void write() { mGroup.deleteGroup(); - QMap::ConstIterator it = mMap.constBegin(), end = mMap.constEnd(); + QMap::ConstIterator it = mMap.constBegin(), end = mMap.constEnd(); int idx = 0; for (; it != end; ++it, ++idx) { QString idxString = QString::number(idx); - mGroup.writeEntry(idxString + QLatin1String(KEY_SUFFIX), it.key().url()); - mGroup.writeEntry(idxString + QLatin1String(VALUE_SUFFIX), it.value().url()); + mGroup.writeEntry(idxString + QLatin1String(KEY_SUFFIX), QVariant(it.key())); + mGroup.writeEntry(idxString + QLatin1String(VALUE_SUFFIX), QVariant(it.value())); } mGroup.sync(); } }; SerializedUrlMap::SerializedUrlMap() : d(new SerializedUrlMapPrivate) { } SerializedUrlMap::~SerializedUrlMap() { delete d; } void SerializedUrlMap::setConfigGroup(const KConfigGroup& group) { d->mGroup = group; d->read(); } -KUrl SerializedUrlMap::value(const KUrl& key_) const +QUrl SerializedUrlMap::value(const QUrl& key_) const { - QString pass = key_.pass(); - KUrl key = stripPass(key_); - KUrl url = d->mMap.value(key); - url.setPass(pass); + QString pass = key_.password(); + QUrl key = stripPass(key_); + QUrl url = d->mMap.value(key); + url.setPassword(pass); return url; } -void SerializedUrlMap::insert(const KUrl& key, const KUrl& value) +void SerializedUrlMap::insert(const QUrl& key, const QUrl& value) { d->mMap.insert(stripPass(key), stripPass(value)); d->write(); } } // namespace diff --git a/importer/serializedurlmap.h b/importer/serializedurlmap.h index d15918db..b50927e4 100644 --- a/importer/serializedurlmap.h +++ b/importer/serializedurlmap.h @@ -1,58 +1,58 @@ // vim: set tabstop=4 shiftwidth=4 expandtab: /* Gwenview: an image viewer Copyright 2012 Aurélien Gâteau This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA. */ #ifndef SERIALIZEDURLMAP_H #define SERIALIZEDURLMAP_H // Local // KDE // Qt class KConfigGroup; -class KUrl; +class QUrl; namespace Gwenview { struct SerializedUrlMapPrivate; /** - * A map-like KUrl=>KUrl object, serialized in a KConfigGroup + * A map-like QUrl=>QUrl object, serialized in a KConfigGroup */ class SerializedUrlMap { public: SerializedUrlMap(); ~SerializedUrlMap(); void setConfigGroup(const KConfigGroup&); - KUrl value(const KUrl&) const; + QUrl value(const QUrl&) const; - void insert(const KUrl& key, const KUrl& value); + void insert(const QUrl& key, const QUrl& value); private: SerializedUrlMapPrivate* const d; }; } // namespace #endif /* SERIALIZEDURLMAP_H */ diff --git a/importer/thumbnailpage.cpp b/importer/thumbnailpage.cpp index 31e1d7f8..bd7c7ad7 100644 --- a/importer/thumbnailpage.cpp +++ b/importer/thumbnailpage.cpp @@ -1,455 +1,460 @@ // vim: set tabstop=4 shiftwidth=4 expandtab: /* Gwenview: an image viewer Copyright 2009 Aurélien Gâteau This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA. */ // Self -#include "thumbnailpage.moc" +#include "thumbnailpage.h" // Qt +#include +#include #include #include // KDE #include #include #include #include #include #include +#include #include // Local #include #include #include #include #include #include #include #include #include #include #include #include namespace Gwenview { static const int DEFAULT_THUMBNAIL_SIZE = 128; static const qreal DEFAULT_THUMBNAIL_ASPECT_RATIO = 3. / 2.; static const char* URL_FOR_BASE_URL_GROUP = "UrlForBaseUrl"; class ImporterThumbnailViewHelper : public AbstractThumbnailViewHelper { public: ImporterThumbnailViewHelper(QObject* parent) : AbstractThumbnailViewHelper(parent) {} void showContextMenu(QWidget*) {} - void showMenuForUrlDroppedOnViewport(QWidget*, const KUrl::List&) + void showMenuForUrlDroppedOnViewport(QWidget*, const QList&) {} - void showMenuForUrlDroppedOnDir(QWidget*, const KUrl::List&, const KUrl&) + void showMenuForUrlDroppedOnDir(QWidget*, const QList&, const QUrl&) {} }; inline KFileItem itemForIndex(const QModelIndex& index) { return index.data(KDirModel::FileItemRole).value(); } struct ThumbnailPagePrivate : public Ui_ThumbnailPage { ThumbnailPage* q; SerializedUrlMap mUrlMap; - KIcon mSrcBaseIcon; + QIcon mSrcBaseIcon; QString mSrcBaseName; - KUrl mSrcBaseUrl; - KUrl mSrcUrl; + QUrl mSrcBaseUrl; + QUrl mSrcUrl; KModelIndexProxyMapper* mSrcUrlModelProxyMapper; RecursiveDirModel* mRecursiveDirModel; QAbstractItemModel* mFinalModel; ThumbnailProvider mThumbnailProvider; QPushButton* mImportSelectedButton; QPushButton* mImportAllButton; - KUrl::List mUrlList; + QList mUrlList; void setupDirModel() { mRecursiveDirModel = new RecursiveDirModel(q); KindProxyModel* kindProxyModel = new KindProxyModel(q); kindProxyModel->setKindFilter( MimeTypeUtils::KIND_RASTER_IMAGE | MimeTypeUtils::KIND_SVG_IMAGE | MimeTypeUtils::KIND_VIDEO); kindProxyModel->setSourceModel(mRecursiveDirModel); QSortFilterProxyModel *sortModel = new QSortFilterProxyModel(q); sortModel->setDynamicSortFilter(true); sortModel->setSourceModel(kindProxyModel); sortModel->sort(0); mFinalModel = sortModel; QObject::connect( mFinalModel, SIGNAL(rowsInserted(QModelIndex,int,int)), q, SLOT(updateImportButtons())); QObject::connect( mFinalModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), q, SLOT(updateImportButtons())); QObject::connect( mFinalModel, SIGNAL(modelReset()), q, SLOT(updateImportButtons())); } void setupIcons() { const KIconLoader::Group group = KIconLoader::NoGroup; const int size = KIconLoader::SizeHuge; mSrcIconLabel->setPixmap(KIconLoader::global()->loadIcon("camera-photo", group, size)); mDstIconLabel->setPixmap(KIconLoader::global()->loadIcon("computer", group, size)); } void setupSrcUrlWidgets() { mSrcUrlModelProxyMapper = 0; QObject::connect(mSrcUrlButton, SIGNAL(clicked()), q, SLOT(setupSrcUrlTreeView())); QObject::connect(mSrcUrlButton, SIGNAL(clicked()), q, SLOT(toggleSrcUrlTreeView())); mSrcUrlTreeView->hide(); KAcceleratorManager::setNoAccel(mSrcUrlButton); } void setupDstUrlRequester() { mDstUrlRequester->setMode(KFile::Directory | KFile::LocalOnly); } void setupThumbnailView() { mThumbnailView->setModel(mFinalModel); mThumbnailView->setSelectionMode(QAbstractItemView::ExtendedSelection); mThumbnailView->setThumbnailViewHelper(new ImporterThumbnailViewHelper(q)); PreviewItemDelegate* delegate = new PreviewItemDelegate(mThumbnailView); delegate->setThumbnailDetails(PreviewItemDelegate::FileNameDetail); delegate->setContextBarActions(PreviewItemDelegate::SelectionAction); mThumbnailView->setItemDelegate(delegate); // Colors int value = GwenviewConfig::viewBackgroundValue(); QColor bgColor = QColor::fromHsv(0, 0, value); QColor fgColor = value > 128 ? Qt::black : Qt::white; QPalette pal = mThumbnailView->palette(); pal.setColor(QPalette::Base, bgColor); pal.setColor(QPalette::Text, fgColor); mThumbnailView->setPalette(pal); QObject::connect(mSlider, SIGNAL(valueChanged(int)), mThumbnailView, SLOT(setThumbnailWidth(int))); QObject::connect(mThumbnailView, SIGNAL(thumbnailWidthChanged(int)), mSlider, SLOT(setValue(int))); int thumbnailSize = DEFAULT_THUMBNAIL_SIZE; mSlider->setValue(thumbnailSize); mSlider->updateToolTip(); mThumbnailView->setThumbnailAspectRatio(DEFAULT_THUMBNAIL_ASPECT_RATIO); mThumbnailView->setThumbnailWidth(thumbnailSize); mThumbnailView->setThumbnailProvider(&mThumbnailProvider); QObject::connect( mThumbnailView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), q, SLOT(updateImportButtons())); } void setupButtonBox() { QObject::connect(mConfigureButton, SIGNAL(clicked()), q, SLOT(showConfigDialog())); mImportSelectedButton = mButtonBox->addButton( i18n("Import Selected"), QDialogButtonBox::AcceptRole, q, SLOT(slotImportSelected())); mImportAllButton = mButtonBox->addButton( i18n("Import All"), QDialogButtonBox::AcceptRole, q, SLOT(slotImportAll())); QObject::connect( mButtonBox, SIGNAL(rejected()), q, SIGNAL(rejected())); } - KUrl urlForBaseUrl() const + QUrl urlForBaseUrl() const { - KUrl url = mUrlMap.value(mSrcBaseUrl); + QUrl url = mUrlMap.value(mSrcBaseUrl); if (!url.isValid()) { - return KUrl(); + return QUrl(); } KIO::UDSEntry entry; bool ok = KIO::NetAccess::stat(url, entry, q); if (!ok) { - return KUrl(); + return QUrl(); } KFileItem item(entry, url, true /* delayedMimeTypes */); - return item.isDir() ? url : KUrl(); + return item.isDir() ? url : QUrl(); } - void rememberUrl(const KUrl& url) + void rememberUrl(const QUrl& url) { mUrlMap.insert(mSrcBaseUrl, url); } }; ThumbnailPage::ThumbnailPage() : d(new ThumbnailPagePrivate) { d->q = this; d->mUrlMap.setConfigGroup(KConfigGroup(KSharedConfig::openConfig(), URL_FOR_BASE_URL_GROUP)); d->setupUi(this); d->setupIcons(); d->setupDirModel(); d->setupSrcUrlWidgets(); d->setupDstUrlRequester(); d->setupThumbnailView(); d->setupButtonBox(); updateImportButtons(); } ThumbnailPage::~ThumbnailPage() { delete d; } -void ThumbnailPage::setSourceUrl(const KUrl& srcBaseUrl, const QString& iconName, const QString& name) +void ThumbnailPage::setSourceUrl(const QUrl& srcBaseUrl, const QString& iconName, const QString& name) { - d->mSrcBaseIcon = KIcon(iconName); + d->mSrcBaseIcon = QIcon(iconName); d->mSrcBaseName = name; const int size = KIconLoader::SizeHuge; d->mSrcIconLabel->setPixmap(d->mSrcBaseIcon.pixmap(size)); d->mSrcBaseUrl = srcBaseUrl; - d->mSrcBaseUrl.adjustPath(KUrl::AddTrailingSlash); - KUrl url = d->urlForBaseUrl(); + if (!d->mSrcBaseUrl.path().endsWith('/')) { + d->mSrcBaseUrl.setPath(d->mSrcBaseUrl.path() + '/'); + } + QUrl url = d->urlForBaseUrl(); if (url.isValid()) { openUrl(url); } else { DocumentDirFinder* finder = new DocumentDirFinder(srcBaseUrl); - connect(finder, SIGNAL(done(KUrl,DocumentDirFinder::Status)), - SLOT(slotDocumentDirFinderDone(KUrl,DocumentDirFinder::Status))); + connect(finder, SIGNAL(done(QUrl,DocumentDirFinder::Status)), + SLOT(slotDocumentDirFinderDone(QUrl,DocumentDirFinder::Status))); finder->start(); } } -void ThumbnailPage::slotDocumentDirFinderDone(const KUrl& url, DocumentDirFinder::Status /*status*/) +void ThumbnailPage::slotDocumentDirFinderDone(const QUrl& url, DocumentDirFinder::Status /*status*/) { d->rememberUrl(url); openUrl(url); } -void ThumbnailPage::openUrl(const KUrl& url) +void ThumbnailPage::openUrl(const QUrl& url) { d->mSrcUrl = url; - QString path = KUrl::relativeUrl(d->mSrcBaseUrl, d->mSrcUrl); + QString path = QDir(d->mSrcBaseUrl.path()).relativeFilePath(d->mSrcUrl.path()); QString text; if (path.isEmpty() || path == "./") { text = d->mSrcBaseName; } else { path = QUrl::fromPercentEncoding(path.toUtf8()); path.replace("/", QString::fromUtf8(" › ")); text = QString::fromUtf8("%1 › %2").arg(d->mSrcBaseName).arg(path); } d->mSrcUrlButton->setText(text); d->mRecursiveDirModel->setUrl(url); } -KUrl::List ThumbnailPage::urlList() const +QList ThumbnailPage::urlList() const { return d->mUrlList; } -void ThumbnailPage::setDestinationUrl(const KUrl& url) +void ThumbnailPage::setDestinationUrl(const QUrl& url) { d->mDstUrlRequester->setUrl(url); } -KUrl ThumbnailPage::destinationUrl() const +QUrl ThumbnailPage::destinationUrl() const { return d->mDstUrlRequester->url(); } void ThumbnailPage::slotImportSelected() { importList(d->mThumbnailView->selectionModel()->selectedIndexes()); } void ThumbnailPage::slotImportAll() { QModelIndexList list; QAbstractItemModel* model = d->mThumbnailView->model(); for (int row = model->rowCount() - 1; row >= 0; --row) { list << model->index(row, 0); } importList(list); } void ThumbnailPage::importList(const QModelIndexList& list) { d->mUrlList.clear(); Q_FOREACH(const QModelIndex & index, list) { KFileItem item = itemForIndex(index); if (!ArchiveUtils::fileItemIsDirOrArchive(item)) { d->mUrlList << item.url(); } // FIXME: Handle dirs (do we want to import recursively?) } emit importRequested(); } void ThumbnailPage::updateImportButtons() { d->mImportSelectedButton->setEnabled(d->mThumbnailView->selectionModel()->hasSelection()); d->mImportAllButton->setEnabled(d->mThumbnailView->model()->rowCount(QModelIndex()) > 0); } void ThumbnailPage::showConfigDialog() { ImporterConfigDialog dialog(this); dialog.exec(); } /** * This model allows only the url passed in the constructor to appear at the root * level. This makes it possible to select the url, but not its siblings. * It also provides custom role values for the root item. */ class OnlyBaseUrlProxyModel : public QSortFilterProxyModel { public: - OnlyBaseUrlProxyModel(const KUrl& url, const KIcon& icon, const QString& name, QObject* parent) + OnlyBaseUrlProxyModel(const QUrl& url, const QIcon& icon, const QString& name, QObject* parent) : QSortFilterProxyModel(parent) , mUrl(url) , mIcon(icon) , mName(name) {} bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const // reimp { if (sourceParent.isValid()) { return true; } QModelIndex index = sourceModel()->index(sourceRow, 0); KFileItem item = itemForIndex(index); - return item.url().equals(mUrl, KUrl::CompareWithoutTrailingSlash); + return item.url().matches(mUrl, QUrl::StripTrailingSlash); } QVariant data(const QModelIndex& index, int role) const // reimp { if (index.parent().isValid()) { return QSortFilterProxyModel::data(index, role); } switch (role) { case Qt::DisplayRole: return mName; case Qt::DecorationRole: return mIcon; case Qt::ToolTipRole: - return mUrl.pathOrUrl(); + return mUrl.toDisplayString(QUrl::PreferLocalFile); default: return QSortFilterProxyModel::data(index, role); } } private: - KUrl mUrl; - KIcon mIcon; + QUrl mUrl; + QIcon mIcon; QString mName; }; void ThumbnailPage::setupSrcUrlTreeView() { if (d->mSrcUrlTreeView->model()) { // Already initialized return; } KDirModel* dirModel = new KDirModel(this); dirModel->dirLister()->setDirOnlyMode(true); - dirModel->dirLister()->openUrl(d->mSrcBaseUrl.upUrl()); + dirModel->dirLister()->openUrl(KIO::upUrl(d->mSrcBaseUrl)); OnlyBaseUrlProxyModel* onlyBaseUrlModel = new OnlyBaseUrlProxyModel(d->mSrcBaseUrl, d->mSrcBaseIcon, d->mSrcBaseName, this); onlyBaseUrlModel->setSourceModel(dirModel); QSortFilterProxyModel* sortModel = new QSortFilterProxyModel(this); sortModel->setDynamicSortFilter(true); sortModel->setSourceModel(onlyBaseUrlModel); sortModel->sort(0); d->mSrcUrlModelProxyMapper = new KModelIndexProxyMapper(dirModel, sortModel, this); d->mSrcUrlTreeView->setModel(sortModel); for(int i = 1; i < dirModel->columnCount(); ++i) { d->mSrcUrlTreeView->hideColumn(i); } connect(d->mSrcUrlTreeView, SIGNAL(activated(QModelIndex)), SLOT(openUrlFromIndex(QModelIndex))); connect(d->mSrcUrlTreeView, SIGNAL(clicked(QModelIndex)), SLOT(openUrlFromIndex(QModelIndex))); dirModel->expandToUrl(d->mSrcUrl); connect(dirModel, SIGNAL(expand(QModelIndex)), SLOT(slotSrcUrlModelExpand(QModelIndex))); } void ThumbnailPage::slotSrcUrlModelExpand(const QModelIndex& index) { QModelIndex viewIndex = d->mSrcUrlModelProxyMapper->mapLeftToRight(index); d->mSrcUrlTreeView->expand(viewIndex); KFileItem item = itemForIndex(index); if (item.url() == d->mSrcUrl) { d->mSrcUrlTreeView->selectionModel()->select(viewIndex, QItemSelectionModel::ClearAndSelect); } } void ThumbnailPage::toggleSrcUrlTreeView() { d->mSrcUrlTreeView->setVisible(!d->mSrcUrlTreeView->isVisible()); } void ThumbnailPage::openUrlFromIndex(const QModelIndex& index) { KFileItem item = itemForIndex(index); if (item.isNull()) { return; } - KUrl url = item.url(); + QUrl url = item.url(); d->rememberUrl(url); openUrl(url); } } // namespace diff --git a/importer/thumbnailpage.h b/importer/thumbnailpage.h index 4f74482a..95d50066 100644 --- a/importer/thumbnailpage.h +++ b/importer/thumbnailpage.h @@ -1,80 +1,80 @@ // vim: set tabstop=4 shiftwidth=4 expandtab: /* Gwenview: an image viewer Copyright 2009 Aurélien Gâteau This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA. */ #ifndef THUMBNAILPAGE_H #define THUMBNAILPAGE_H // Qt #include +#include #include // KDE -#include // Local #include "documentdirfinder.h" namespace Gwenview { struct ThumbnailPagePrivate; class ThumbnailPage : public QWidget { Q_OBJECT public: ThumbnailPage(); ~ThumbnailPage(); /** * Returns the list of urls to import * Only valid after importRequested() has been emitted */ - KUrl::List urlList() const; + QList urlList() const; - KUrl destinationUrl() const; - void setDestinationUrl(const KUrl&); + QUrl destinationUrl() const; + void setDestinationUrl(const QUrl&); - void setSourceUrl(const KUrl&, const QString& icon, const QString& label); + void setSourceUrl(const QUrl&, const QString& icon, const QString& label); Q_SIGNALS: void importRequested(); void rejected(); private Q_SLOTS: void slotImportSelected(); void slotImportAll(); void updateImportButtons(); - void openUrl(const KUrl&); - void slotDocumentDirFinderDone(const KUrl& url, DocumentDirFinder::Status status); + void openUrl(const QUrl&); + void slotDocumentDirFinderDone(const QUrl& url, DocumentDirFinder::Status status); void showConfigDialog(); void openUrlFromIndex(const QModelIndex& index); void setupSrcUrlTreeView(); void toggleSrcUrlTreeView(); void slotSrcUrlModelExpand(const QModelIndex& index); private: friend struct ThumbnailPagePrivate; ThumbnailPagePrivate* const d; void importList(const QModelIndexList&); }; } // namespace #endif /* THUMBNAILPAGE_H */