File indexing completed on 2021-12-21 13:15:44

0001 /***************************************************************************
0002 *   Copyright 2007 Niko Sams <niko.sams@gmail.com>                        *
0003 *                                                                         *
0004 *   This program is free software; you can redistribute it and/or modify  *
0005 *   it under the terms of the GNU General Public License as published by  *
0006 *   the Free Software Foundation; either version 2 of the License, or     *
0007 *   (at your option) any later version.                                   *
0008 *                                                                         *
0009 ***************************************************************************/
0010 #include "uploadpreferences.h"
0011 
0012 #include <QVBoxLayout>
0013 #include <QStandardItemModel>
0014 
0015 #include <interfaces/icore.h>
0016 #include <interfaces/iplugincontroller.h>
0017 #include <interfaces/iprojectcontroller.h>
0018 #include <interfaces/iproject.h>
0019 #include <util/path.h>
0020 
0021 #include "uploadprofilemodel.h"
0022 #include "ui_uploadpreferences.h"
0023 #include "uploadprofiledlg.h"
0024 #include "uploadprofileitem.h"
0025 
0026 using namespace KDevelop;
0027 
0028 UploadPreferences::UploadPreferences( KDevelop::IPlugin* plugin, const KDevelop::ProjectConfigOptions& options, QWidget* parent )
0029     : ProjectConfigPage<UploadSettings>(plugin, options, parent)
0030 {
0031     IProject* project = options.project;
0032 
0033     m_ui = new Ui::UploadPreferences();
0034     m_ui->setupUi(this);
0035 
0036     m_model = new UploadProfileModel();
0037     m_model->setProject(project);
0038     m_ui->profilesList->setModel(m_model);
0039 
0040 
0041     connect(m_model, SIGNAL(dataChanged(QModelIndex, QModelIndex)),
0042             this, SLOT(changed()));
0043     connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)),
0044             this, SLOT(changed()));
0045 
0046     connect(m_ui->addProfileButton, SIGNAL(clicked()),
0047               this, SLOT(addProfile()));
0048     connect(m_ui->modifyProfileButton, SIGNAL(clicked()),
0049               this, SLOT(modifyProfile()));
0050     connect(m_ui->removeProfileButton, SIGNAL(clicked()),
0051               this, SLOT(removeProfile()));
0052     connect(m_ui->profilesList, SIGNAL(doubleClicked(QModelIndex)),
0053             this, SLOT(modifyProfile()));
0054 
0055     m_dlg = new UploadProfileDlg(this);
0056 }
0057 
0058 UploadPreferences::~UploadPreferences( )
0059 {
0060   delete m_ui;
0061 }
0062 
0063 void UploadPreferences::reset()
0064 {
0065     ProjectConfigPage::reset();
0066 }
0067 
0068 void UploadPreferences::apply()
0069 {
0070     m_model->submit();
0071     m_model->revert();
0072     ProjectConfigPage::apply();
0073 }
0074 
0075 void UploadPreferences::defaults()
0076 {
0077     ProjectConfigPage::defaults();
0078 }
0079 
0080 void UploadPreferences::addProfile()
0081 {
0082     UploadProfileItem* i = new UploadProfileItem();
0083     i->setLocalUrl(QUrl(m_model->project()->path().path()));
0084     if (m_model->rowCount() == 0) {
0085         i->setDefault(true);
0086     }
0087     m_model->appendRow(i);
0088     if (m_dlg->editProfile(i) == QDialog::Rejected) {
0089         m_model->removeRow(i->index().row());
0090     }
0091 }
0092 
0093 void UploadPreferences::removeProfile()
0094 {
0095     Q_FOREACH(QModelIndex index, m_ui->profilesList->selectionModel()->selectedIndexes()) {
0096         m_model->removeRow(index.row());
0097     }
0098 }
0099 
0100 void UploadPreferences::modifyProfile()
0101 {
0102     Q_FOREACH(QModelIndex index, m_ui->profilesList->selectionModel()->selectedIndexes()) {
0103         UploadProfileItem* i = m_model->uploadItem(index);
0104         if (i) {
0105             m_dlg->editProfile(i);
0106         }
0107     }
0108 }
0109 
0110 QString UploadPreferences::name() const
0111 {
0112     return i18n("Upload");
0113 }
0114 
0115 QString UploadPreferences::fullName() const
0116 {
0117     return i18n("Configure Upload settings");
0118 }
0119 
0120 QIcon UploadPreferences::icon() const
0121 {
0122     return QIcon::fromTheme(QStringLiteral("go-up"));
0123 }
0124 
0125 // kate: space-indent on; indent-width 4; tab-width 4; replace-tabs on