diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,11 +18,14 @@ include(KDEInstallDirs) include(KDECMakeSettings) include(FeatureSummary) +include(ECMQtDeclareLoggingCategory) +include(KDECMakeSettings) +include(WriteBasicConfigVersionFile) set(QT_MIN_VERSION "5.5.0") find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED Core Widgets) set(KF5_DEP_VERSION "5.15.0") -find_package(KF5 ${KF5_DEP_VERSION} REQUIRED COMPONENTS TextEditor I18n KCMUtils JobWidgets Service Parts KIO CoreAddons ItemModels) +find_package(KF5 ${KF5_DEP_VERSION} REQUIRED COMPONENTS Config TextEditor I18n KCMUtils JobWidgets Service Parts KIO CoreAddons ItemModels XmlGui) find_package(KDevPlatform ${KDEVPLATFORM_VERSION} REQUIRED) include_directories( @@ -43,12 +46,23 @@ uploadprofileitem.cpp uploadprofilemodel.cpp uploadprojectmodel.cpp + uploadpreferences.cpp ) set(kdevupload_UI uploaddialog.ui uploadprofiledlg.ui + uploadpreferences.ui +) + +ecm_qt_declare_logging_category(projectfilter_SRCS + HEADER debug.h + IDENTIFIER PLUGIN_PROJECTFILTER + CATEGORY_NAME "kdevelop.plugins.upload" ) +ki18n_wrap_ui(uploadpreferences_PART_SRCS uploadpreferences.ui uploadprofiledlg.ui uploaddialog.ui) +kconfig_add_kcfg_files( kdevupload_PART_SRCS uploadconfig.kcfgc ) + add_library(kdevupload_PART_SRCS ${kdevupload_UI}) qt5_add_resources(kdevupload_PART_SRCS kdevupload.qrc) @@ -67,32 +81,3 @@ KF5::KIONTLM KF5::CoreAddons ) - -#preferences-plugin -set(uploadpreferences_PART_SRCS - uploadpreferences.cpp - uploadprofilemodel.cpp - uploadprofileitem.cpp - uploadprofiledlg.cpp -) -ki18n_wrap_ui(uploadpreferences_PART_SRCS uploadpreferences.ui uploadprofiledlg.ui uploaddialog.ui) -add_library(uploadpreferences_PART_SRCS uploadpreferences.ui uploadprofiledlg.ui uploaddialog.ui) - -add_library(kcm_kdev_upload ${uploadpreferences_PART_SRCS}) - -target_link_libraries(kcm_kdev_upload - KDev::Interfaces - KDev::Util - - KF5::I18n - KF5::KCMUtils - KF5::Service - KF5::Parts - KF5::KIOCore - KF5::KIOFileWidgets - KF5::KIOWidgets - KF5::KIONTLM -) - -install(TARGETS kcm_kdev_upload DESTINATION ${PLUGIN_INSTALL_DIR}) -install(FILES kcm_kdev_upload.desktop DESTINATION ${SERVICES_INSTALL_DIR}) diff --git a/kdevuploadplugin.h b/kdevuploadplugin.h --- a/kdevuploadplugin.h +++ b/kdevuploadplugin.h @@ -35,7 +35,6 @@ public: UploadPlugin(QObject *parent, const QVariantList & = QVariantList() ); ~UploadPlugin() override; - void unload() override; /** * Returns the Upload-Action for the Contextmenu. @@ -47,6 +46,9 @@ * Creates the output-view (only the first time called) */ QStandardItemModel* outputModel(); + + int perProjectConfigPages() const override; + KDevelop::ConfigPage* perProjectConfigPage(int number, const KDevelop::ProjectConfigOptions& options, QWidget* parent) override; private Q_SLOTS: /** diff --git a/kdevuploadplugin.cpp b/kdevuploadplugin.cpp --- a/kdevuploadplugin.cpp +++ b/kdevuploadplugin.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -40,6 +41,7 @@ #include "uploadprojectmodel.h" #include "uploadprofilemodel.h" #include "uploadprofileitem.h" +#include "uploadpreferences.h" #include "allprofilesmodel.h" #include @@ -193,10 +195,6 @@ } } -void UploadPlugin::unload() -{ -} - KDevelop::ContextMenuExtension UploadPlugin::contextMenuExtension(KDevelop::Context* context, QWidget* parent) { if (context->type() == KDevelop::Context::ProjectItemContext) { @@ -232,6 +230,17 @@ return KDevelop::IPlugin::contextMenuExtension(context, parent); } +int UploadPlugin::perProjectConfigPages() const +{ + return 1; +} + + +KDevelop::ConfigPage* UploadPlugin::perProjectConfigPage(int number, const KDevelop::ProjectConfigOptions& options, QWidget* parent) +{ + return number == 0 ? new UploadPreferences(this, options, parent) : nullptr; +} + void UploadPlugin::upload() { if (m_ctxUrlList.isEmpty()) return; diff --git a/uploadconfig.kcfg b/uploadconfig.kcfg new file mode 100644 --- /dev/null +++ b/uploadconfig.kcfg @@ -0,0 +1,7 @@ + + + + diff --git a/uploadconfig.kcfgc b/uploadconfig.kcfgc new file mode 100644 --- /dev/null +++ b/uploadconfig.kcfgc @@ -0,0 +1,9 @@ +File=uploadconfig.kcfg +ClassName=UploadSettings +Singleton=true +Mutators=true +SetUserTexts=true +ItemAccessors=true +Inherits=KDevelop::ProjectConfigSkeleton +IncludeFiles=project/projectconfigskeleton.h +SourceIncludeFiles=uploadpreferences.h diff --git a/uploadjob.cpp b/uploadjob.cpp --- a/uploadjob.cpp +++ b/uploadjob.cpp @@ -103,14 +103,21 @@ ->data(m_uploadIndex, Qt::CheckStateRole).toInt()); KDevelop::Path url; + QUrl localUrl = m_uploadProjectModel->currentProfileLocalUrl().adjusted(QUrl::StripTrailingSlash); + KDevelop::Path localPath = KDevelop::Path(localUrl.path()); + if (item->folder()) { url = item->folder()->path(); } else if (item->file()) { url = item->file()->path(); } - - QString relativeUrl(m_project->path().relativePath(url)); + + if(localPath.path().isEmpty()) { + localPath = m_project->path(); + } + + QString relativeUrl(localPath.relativePath(url)); if (isQuickUpload() && checked == Qt::Unchecked) { appendLog(i18n("File was not modified for %1: %2", diff --git a/uploadpreferences.h b/uploadpreferences.h --- a/uploadpreferences.h +++ b/uploadpreferences.h @@ -11,10 +11,13 @@ #ifndef UPLOADPREFERENCES_H #define UPLOADPREFERENCES_H -#include #include #include +#include + +#include "uploadconfig.h" + namespace Ui { class UploadPreferences; } @@ -25,15 +28,21 @@ /** * KCModule for upload profiles configuration */ -class UploadPreferences : public KCModule +class UploadPreferences : public ProjectConfigPage { Q_OBJECT public: - UploadPreferences( QWidget *parent, const QVariantList &args = QVariantList() ); + UploadPreferences(KDevelop::IPlugin* plugin, const KDevelop::ProjectConfigOptions& options, QWidget* parent); ~UploadPreferences() override; - void save() override; + void reset() override; + void apply() override; + void defaults() override; + + QString name() const override; + QString fullName() const override; + QIcon icon() const override; private Q_SLOTS: void addProfile(); diff --git a/uploadpreferences.cpp b/uploadpreferences.cpp --- a/uploadpreferences.cpp +++ b/uploadpreferences.cpp @@ -12,9 +12,6 @@ #include #include -#include -#include - #include #include #include @@ -25,39 +22,22 @@ #include "ui_uploadpreferences.h" #include "uploadprofiledlg.h" #include "uploadprofileitem.h" -#include "kdevuploadplugin.h" using namespace KDevelop; -K_PLUGIN_FACTORY(UploadPreferencesFactory, registerPlugin(); ) - -UploadPreferences::UploadPreferences( QWidget *parent, const QVariantList &args ) - : KCModule( parent, args ) +UploadPreferences::UploadPreferences( KDevelop::IPlugin* plugin, const KDevelop::ProjectConfigOptions& options, QWidget* parent ) + : ProjectConfigPage(plugin, options, parent) { - IProject* project = nullptr; - Q_FOREACH (IProject* p, KDevelop::ICore::self()->projectController()->projects()) { - if (p->projectFile().path() == args.at(1).toString()) { - project = p; - break; - } - } - Q_ASSERT(project); - - - setButtons(Help | Apply); - - QVBoxLayout * l = new QVBoxLayout( this ); - setLayout(l); - QWidget* w = new QWidget(); - l->addWidget(w); + IProject* project = options.project; m_ui = new Ui::UploadPreferences(); - m_ui->setupUi(w); + m_ui->setupUi(this); m_model = new UploadProfileModel(); m_model->setProject(project); m_ui->profilesList->setModel(m_model); + connect(m_model, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(changed())); connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), @@ -80,14 +60,27 @@ delete m_ui; } -void UploadPreferences::save() +void UploadPreferences::reset() +{ + ProjectConfigPage::reset(); +} + +void UploadPreferences::apply() { m_model->submit(); + m_model->revert(); + ProjectConfigPage::apply(); +} + +void UploadPreferences::defaults() +{ + ProjectConfigPage::defaults(); } void UploadPreferences::addProfile() { UploadProfileItem* i = new UploadProfileItem(); + i->setLocalUrl(QUrl(m_model->project()->path().path())); if (m_model->rowCount() == 0) { i->setDefault(true); } @@ -114,5 +107,19 @@ } } -#include "uploadpreferences.moc" +QString UploadPreferences::name() const +{ + return i18n("Upload"); +} + +QString UploadPreferences::fullName() const +{ + return i18n("Configure Upload settings"); +} + +QIcon UploadPreferences::icon() const +{ + return QIcon::fromTheme(QStringLiteral("go-up")); +} + // kate: space-indent on; indent-width 4; tab-width 4; replace-tabs on diff --git a/uploadprofiledlg.h b/uploadprofiledlg.h --- a/uploadprofiledlg.h +++ b/uploadprofiledlg.h @@ -42,6 +42,10 @@ * Opens a directory browser to select the path */ void browse(); + /** + * Opens a directory browser to select the local path + */ + void browseLocal(); protected Q_SLOTS: /** @@ -61,6 +65,8 @@ void updateUrl( const QUrl& url ); Ui::UploadProfileDlg* m_ui; + + QUrl* projectPath; }; diff --git a/uploadprofiledlg.cpp b/uploadprofiledlg.cpp --- a/uploadprofiledlg.cpp +++ b/uploadprofiledlg.cpp @@ -38,6 +38,8 @@ m_ui = new Ui::UploadProfileDlg(); m_ui->setupUi(widget); + m_ui->browseButtonLocal->setIcon(QIcon::fromTheme("document-open")); + connect(m_ui->browseButtonLocal, SIGNAL(clicked()), this, SLOT(browseLocal())); m_ui->browseButton->setIcon(QIcon::fromTheme("document-open")); connect(m_ui->browseButton, SIGNAL(clicked()), this, SLOT(browse())); @@ -73,12 +75,15 @@ { m_ui->lineProfileName->setText(item->text()); m_ui->defaultProfile->setChecked(item->isDefault()); + m_ui->lineLocalPath->setText(item->localUrl().toString()); updateUrl(item->url()); int result = exec(); if (result == QDialog::Accepted) { item->setText(m_ui->lineProfileName->text()); item->setUrl(currentUrl()); + QUrl localUrl = QUrl(m_ui->lineLocalPath->text()); + item->setLocalUrl(localUrl); item->setDefault(m_ui->defaultProfile->checkState() == Qt::Checked); } return result; @@ -124,6 +129,23 @@ updateUrl(chosenDir); } } + +void UploadProfileDlg::browseLocal() +{ +#if QT_VERSION >= 0x050400 + QUrl chosenDir = QFileDialog::getExistingDirectoryUrl(this, QString(), m_ui->lineLocalPath->text()); +#else + QFileDialog dialog(this); + dialog.setDirectoryUrl(m_ui->lineLocalPath->text()); + dialog.setOptions(QFileDialog::ShowDirsOnly); + dialog.exec(); + QUrl chosenDir = dialog.selectedUrls().first(); +#endif + if(chosenDir.isValid()) { + m_ui->lineLocalPath->setText(chosenDir.path()); + } +} + void UploadProfileDlg::slotAcceptButtonClicked() { KIO::StatJob* statJob = KIO::stat(currentUrl()); @@ -134,6 +156,14 @@ KMessageBox::sorry(this, i18n("The specified URL does not exist.")); return; } + + //TODO: check if local dir is subpath of project dir + QString selectedLocalPath = m_ui->lineLocalPath->text(); + if(!QDir(selectedLocalPath).exists()) { + KMessageBox::sorry(this, i18n("The specified local directory does not exist.")); + return; + } + QDialog::accept(); } diff --git a/uploadprofiledlg.ui b/uploadprofiledlg.ui --- a/uploadprofiledlg.ui +++ b/uploadprofiledlg.ui @@ -131,6 +131,36 @@ + + + &Local Path: + + + false + + + linePath + + + + + + + + + + + + + 0 + 0 + + + + + + + Pa&th: @@ -143,7 +173,7 @@ - + @@ -160,7 +190,7 @@ - + Use as &default profile diff --git a/uploadprofileitem.h b/uploadprofileitem.h --- a/uploadprofileitem.h +++ b/uploadprofileitem.h @@ -21,13 +21,15 @@ enum { UrlRole = Qt::UserRole+1, IsDefaultRole = Qt::UserRole+2, - ProfileNrRole = Qt::UserRole+3 + ProfileNrRole = Qt::UserRole+3, + LocalUrlRole = Qt::UserRole+4 }; public: UploadProfileItem(); ~UploadProfileItem() override {} void setUrl(const QUrl& url); + void setLocalUrl(const QUrl& url); /** * Set if this item is the default upload-profile. @@ -41,6 +43,7 @@ void setProfileNr(const QString& nr); QUrl url() const; + QUrl localUrl() const; bool isDefault() const; /** diff --git a/uploadprofileitem.cpp b/uploadprofileitem.cpp --- a/uploadprofileitem.cpp +++ b/uploadprofileitem.cpp @@ -26,6 +26,10 @@ { setData(url, UrlRole); } +void UploadProfileItem::setLocalUrl(const QUrl& url) +{ + setData(url, LocalUrlRole); +} void UploadProfileItem::setDefault(bool isDefault) { @@ -55,6 +59,10 @@ { return data(UrlRole).value(); } +QUrl UploadProfileItem::localUrl() const +{ + return data(LocalUrlRole).value(); +} bool UploadProfileItem::isDefault() const { diff --git a/uploadprofilemodel.cpp b/uploadprofilemodel.cpp --- a/uploadprofilemodel.cpp +++ b/uploadprofilemodel.cpp @@ -67,14 +67,16 @@ Q_FOREACH (QString g, group.groupList()) { if (g.startsWith("Profile")) { QUrl url = group.group(g).readEntry("url", QUrl()); + QUrl localUrl = group.group(g).readEntry("localUrl", QUrl()); QString name = group.group(g).readEntry("name", QString()); UploadProfileItem* i = uploadItem(row); if (!i) { i = new UploadProfileItem(); insertRow(row, i); } i->setText(name); i->setUrl(url); + i->setLocalUrl(localUrl); i->setProfileNr(g.mid(7)); //group-name i->setDefault(i->profileNr() == defProfile); ++row; @@ -108,6 +110,7 @@ } KConfigGroup profileGroup = group.group("Profile" + item->profileNr()); profileGroup.writeEntry("url", item->url().toString()); + profileGroup.writeEntry("localUrl", item->localUrl().toString()); profileGroup.writeEntry("name", item->text()); if (item->isDefault()) { defaultProfileNr = item->profileNr(); diff --git a/uploadprojectmodel.h b/uploadprojectmodel.h --- a/uploadprojectmodel.h +++ b/uploadprojectmodel.h @@ -82,6 +82,11 @@ * Returns the url of the current Upload Profile (which is set through setProfileConfigGroup) */ QUrl currentProfileUrl(); + + /** + * Returns the local url of the current Upload Profile (which is set through setProfileConfigGroup) + */ + QUrl currentProfileLocalUrl(); public Q_SLOTS: /** diff --git a/uploadprojectmodel.cpp b/uploadprojectmodel.cpp --- a/uploadprojectmodel.cpp +++ b/uploadprojectmodel.cpp @@ -222,6 +222,11 @@ return m_profileConfigGroup.readEntry("url", QUrl()); } +QUrl UploadProjectModel::currentProfileLocalUrl() +{ + return m_profileConfigGroup.readEntry("localUrl", QUrl()); +} + void UploadProjectModel::checkAll() { setData(index(0, 0), Qt::Checked, Qt::CheckStateRole);