From 7263d8058871be3928a527d8e2a0ae0f83fd5855 Mon Sep 17 00:00:00 2001 From: Martin Rotter <rotter.martinos@gmail.com> Date: Thu, 21 Apr 2016 11:43:51 +0200 Subject: [PATCH] Can rename feeds. --- resources/text/CHANGELOG | 2 +- .../owncloud/gui/formeditowncloudfeed.cpp | 28 +++++++++++++++++++ .../owncloud/gui/formeditowncloudfeed.h | 1 + .../owncloud/gui/formeditowncloudfeed.ui | 23 +++++++++++---- 4 files changed, 48 insertions(+), 6 deletions(-) diff --git a/resources/text/CHANGELOG b/resources/text/CHANGELOG index 5914c583b..2351ca1b2 100755 --- a/resources/text/CHANGELOG +++ b/resources/text/CHANGELOG @@ -3,7 +3,7 @@ Added: -▪ ownCloud plugin now allows to add feeds. +▪ ownCloud plugin now allows to add feeds and rename feeds. 3.2.1 ————— diff --git a/src/services/owncloud/gui/formeditowncloudfeed.cpp b/src/services/owncloud/gui/formeditowncloudfeed.cpp index a06349c33..140b95404 100644 --- a/src/services/owncloud/gui/formeditowncloudfeed.cpp +++ b/src/services/owncloud/gui/formeditowncloudfeed.cpp @@ -41,6 +41,7 @@ FormEditOwnCloudFeed::FormEditOwnCloudFeed(OwnCloudServiceRoot *root, QWidget *p connect(m_ui->m_gbAuthentication, SIGNAL(toggled(bool)), this, SLOT(onAuthenticationSwitched())); connect(m_ui->m_cmbAutoUpdateType, SIGNAL(currentIndexChanged(int)), this, SLOT(onAutoUpdateTypeChanged(int))); connect(m_ui->m_buttonBox, SIGNAL(accepted()), this, SLOT(performAction())); + connect(m_ui->m_txtTitle->lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(onTitleChanged(QString))); } FormEditOwnCloudFeed::~FormEditOwnCloudFeed() { @@ -55,6 +56,8 @@ int FormEditOwnCloudFeed::execForEdit(OwnCloudFeed *input_feed) { } int FormEditOwnCloudFeed::execForAdd(const QString &url) { + m_ui->m_txtTitle->setEnabled(false); + if (!url.isEmpty()) { m_ui->m_txtUrl->lineEdit()->setText(url); } @@ -137,6 +140,11 @@ void FormEditOwnCloudFeed::onPasswordChanged(const QString &new_password) { tr("Password is empty.")); } +void FormEditOwnCloudFeed::onTitleChanged(const QString &title) { + m_ui->m_txtTitle->setStatus(title.isEmpty() ? WidgetWithStatus::Error : WidgetWithStatus::Ok, + title.isEmpty() ? tr("Title is empty.") : tr("Title looks okay.")); +} + void FormEditOwnCloudFeed::initialize() { setWindowIcon(qApp->icons()->fromTheme(QSL("folder-feed"))); setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog | Qt::WindowSystemMenuHint | Qt::WindowTitleHint); @@ -147,6 +155,8 @@ void FormEditOwnCloudFeed::initialize() { m_ui->m_cmbAutoUpdateType->addItem(tr("Auto-update every"), QVariant::fromValue((int) Feed::SpecificAutoUpdate)); m_ui->m_cmbAutoUpdateType->addItem(tr("Do not auto-update at all"), QVariant::fromValue((int) Feed::DontAutoUpdate)); + setTabOrder(m_ui->m_cmbParentCategory, m_ui->m_txtTitle->lineEdit()); + setTabOrder(m_ui->m_txtTitle->lineEdit(), m_ui->m_txtUrl->lineEdit()); setTabOrder(m_ui->m_txtUrl->lineEdit(), m_ui->m_cmbAutoUpdateType); setTabOrder(m_ui->m_cmbAutoUpdateType, m_ui->m_spinAutoUpdateInterval); setTabOrder(m_ui->m_spinAutoUpdateInterval, m_ui->m_gbAuthentication); @@ -174,10 +184,12 @@ void FormEditOwnCloudFeed::loadFeed(OwnCloudFeed *input_feed) { m_ui->m_lblUrl->setEnabled(false); m_ui->m_lblParentCategory->setEnabled(false); m_ui->m_cmbParentCategory->setEnabled(false); + m_ui->m_txtTitle->setEnabled(true); m_ui->m_cmbParentCategory->setCurrentIndex(m_ui->m_cmbParentCategory->findData(QVariant::fromValue((void*) input_feed->parent()))); m_ui->m_cmbAutoUpdateType->setCurrentIndex(m_ui->m_cmbAutoUpdateType->findData(QVariant::fromValue((int) input_feed->autoUpdateType()))); m_ui->m_spinAutoUpdateInterval->setValue(input_feed->autoUpdateInitialInterval()); + m_ui->m_txtTitle->lineEdit()->setText(input_feed->title()); } else { setWindowTitle(tr("Add new feed")); @@ -193,6 +205,17 @@ void FormEditOwnCloudFeed::loadFeed(OwnCloudFeed *input_feed) { } void FormEditOwnCloudFeed::saveFeed() { + bool renamed = false; + + if (m_ui->m_txtTitle->lineEdit()->text() != m_loadedFeed->title()) { + if (!m_root->network()->renameFeed(m_ui->m_txtTitle->lineEdit()->text(), m_loadedFeed->customId())) { + qWarning("ownCloud: Došlo k problému při prejmenování kanálu s ownCloud ID '%d'.", m_loadedFeed->customId()); + } + else { + renamed = true; + } + } + // User edited auto-update status. Save it. OwnCloudFeed *new_feed_data = new OwnCloudFeed(); @@ -200,7 +223,12 @@ void FormEditOwnCloudFeed::saveFeed() { new_feed_data->setAutoUpdateInitialInterval(m_ui->m_spinAutoUpdateInterval->value()); m_loadedFeed->editItself(new_feed_data); + delete new_feed_data; + + if (renamed) { + QTimer::singleShot(200, m_root, SLOT(syncIn())); + } } void FormEditOwnCloudFeed::addNewFeed() { diff --git a/src/services/owncloud/gui/formeditowncloudfeed.h b/src/services/owncloud/gui/formeditowncloudfeed.h index cecebf6bf..d83a0347b 100644 --- a/src/services/owncloud/gui/formeditowncloudfeed.h +++ b/src/services/owncloud/gui/formeditowncloudfeed.h @@ -49,6 +49,7 @@ class FormEditOwnCloudFeed : public QDialog { void onUrlChanged(const QString &new_url); void onUsernameChanged(const QString &new_username); void onPasswordChanged(const QString &new_password); + void onTitleChanged(const QString &title); private: void initialize(); diff --git a/src/services/owncloud/gui/formeditowncloudfeed.ui b/src/services/owncloud/gui/formeditowncloudfeed.ui index b311c9172..c6848a3d8 100644 --- a/src/services/owncloud/gui/formeditowncloudfeed.ui +++ b/src/services/owncloud/gui/formeditowncloudfeed.ui @@ -42,7 +42,7 @@ </property> </widget> </item> - <item row="1" column="0"> + <item row="2" column="0"> <widget class="QLabel" name="m_lblUrl"> <property name="text"> <string>URL</string> @@ -52,10 +52,10 @@ </property> </widget> </item> - <item row="1" column="1"> + <item row="2" column="1"> <widget class="LineEditWithStatus" name="m_txtUrl" native="true"/> </item> - <item row="2" column="0"> + <item row="3" column="0"> <widget class="QLabel" name="label_6"> <property name="text"> <string>Auto-update</string> @@ -65,7 +65,7 @@ </property> </widget> </item> - <item row="2" column="1"> + <item row="3" column="1"> <layout class="QHBoxLayout" name="horizontalLayout"> <item> <widget class="QComboBox" name="m_cmbAutoUpdateType"> @@ -83,7 +83,7 @@ </item> </layout> </item> - <item row="3" column="0" colspan="2"> + <item row="4" column="0" colspan="2"> <widget class="QGroupBox" name="m_gbAuthentication"> <property name="toolTip"> <string>Some feeds require authentication, including GMail feeds. BASIC, NTLM-2 and DIGEST-MD5 authentication schemes are supported.</string> @@ -130,6 +130,19 @@ </layout> </widget> </item> + <item row="1" column="1"> + <widget class="LineEditWithStatus" name="m_txtTitle" native="true"/> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Title</string> + </property> + <property name="buddy"> + <cstring>m_txtTitle</cstring> + </property> + </widget> + </item> </layout> </item> <item>