Add new dialog.

This commit is contained in:
Martin Rotter 2015-12-18 12:42:24 +01:00
parent 31fdc92167
commit 0bdc594fa5
3 changed files with 445 additions and 0 deletions

View File

@ -0,0 +1,189 @@
// This file is part of RSS Guard.
//
// Copyright (C) 2011-2015 by Martin Rotter <rotter.martinos@gmail.com>
//
// RSS Guard 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 3 of the License, or
// (at your option) any later version.
//
// RSS Guard 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 RSS Guard. If not, see <http://www.gnu.org/licenses/>.
#include "services/tt-rss/gui/formeditfeed.h"
#include "services/abstract/category.h"
#include "services/tt-rss/ttrssfeed.h"
#include "services/tt-rss/ttrssserviceroot.h"
#include "miscellaneous/iconfactory.h"
#include "miscellaneous/application.h"
#include <QClipboard>
#include <QMimeData>
FormEditFeed::FormEditFeed(TtRssServiceRoot *root, QWidget *parent)
: QDialog(parent), m_ui(new Ui::FormEditFeed), m_root(root) {
m_ui->setupUi(this);
initialize();
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()));
}
FormEditFeed::~FormEditFeed() {
delete m_ui;
}
int FormEditFeed::execForEdit(TtRssFeed *input_feed) {
loadCategories(m_root->getSubTreeCategories(), m_root);
loadFeed(input_feed);
return QDialog::exec();
}
int FormEditFeed::execForAdd() {
if (qApp->clipboard()->mimeData()->hasText()) {
m_ui->m_txtUrl->lineEdit()->setText(qApp->clipboard()->text());
}
// TODO: todo
return QDialog::exec();
}
void FormEditFeed::onAuthenticationSwitched() {
onUsernameChanged(m_ui->m_txtUsername->lineEdit()->text());
onPasswordChanged(m_ui->m_txtPassword->lineEdit()->text());
}
void FormEditFeed::onAutoUpdateTypeChanged(int new_index) {
Feed::AutoUpdateType auto_update_type = static_cast<Feed::AutoUpdateType>(m_ui->m_cmbAutoUpdateType->itemData(new_index).toInt());
switch (auto_update_type) {
case Feed::DontAutoUpdate:
case Feed::DefaultAutoUpdate:
m_ui->m_spinAutoUpdateInterval->setEnabled(false);
break;
case Feed::SpecificAutoUpdate:
default:
m_ui->m_spinAutoUpdateInterval->setEnabled(true);
}
}
void FormEditFeed::performAction() {
if (m_loadedFeed != NULL) {
// Edit given feed.
saveFeed();
}
else {
// TODO: Add new feed.
}
accept();
}
void FormEditFeed::onUrlChanged(const QString &new_url) {
if (QRegExp(URL_REGEXP).exactMatch(new_url)) {
// New url is well-formed.
m_ui->m_txtUrl->setStatus(LineEditWithStatus::Ok, tr("The url is ok."));
}
else if (!new_url.isEmpty()) {
// New url is not well-formed but is not empty on the other hand.
m_ui->m_txtUrl->setStatus(LineEditWithStatus::Warning, tr("The url does not meet standard pattern. Does your url start with \"http://\" or \"https://\" prefix."));
}
else {
// New url is empty.
m_ui->m_txtUrl->setStatus(LineEditWithStatus::Error, tr("The url is empty."));
}
}
void FormEditFeed::onUsernameChanged(const QString &new_username) {
bool is_username_ok = !m_ui->m_gbAuthentication->isChecked() || !new_username.isEmpty();
m_ui->m_txtUsername->setStatus(is_username_ok ?
LineEditWithStatus::Ok :
LineEditWithStatus::Warning,
is_username_ok ?
tr("Username is ok or it is not needed.") :
tr("Username is empty."));
}
void FormEditFeed::onPasswordChanged(const QString &new_password) {
bool is_password_ok = !m_ui->m_gbAuthentication->isChecked() || !new_password.isEmpty();
m_ui->m_txtPassword->setStatus(is_password_ok ?
LineEditWithStatus::Ok :
LineEditWithStatus::Warning,
is_password_ok ?
tr("Password is ok or it is not needed.") :
tr("Password is empty."));
}
void FormEditFeed::initialize() {
setWindowIcon(qApp->icons()->fromTheme(QSL("folder-feed")));
setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog | Qt::WindowSystemMenuHint | Qt::WindowTitleHint);
// Setup auto-update options.
m_ui->m_spinAutoUpdateInterval->setValue(DEFAULT_AUTO_UPDATE_INTERVAL);
m_ui->m_cmbAutoUpdateType->addItem(tr("Auto-update using global interval"), QVariant::fromValue((int) Feed::DefaultAutoUpdate));
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_txtUrl->lineEdit(), m_ui->m_cmbAutoUpdateType);
setTabOrder(m_ui->m_cmbAutoUpdateType, m_ui->m_spinAutoUpdateInterval);
setTabOrder(m_ui->m_spinAutoUpdateInterval, m_ui->m_gbAuthentication);
setTabOrder(m_ui->m_gbAuthentication, m_ui->m_txtUsername->lineEdit());
setTabOrder(m_ui->m_txtUsername->lineEdit(), m_ui->m_txtPassword->lineEdit());
setTabOrder(m_ui->m_txtPassword->lineEdit(), m_ui->m_buttonBox);
m_ui->m_txtUrl->lineEdit()->setPlaceholderText(tr("Full feed url including scheme"));
m_ui->m_txtUsername->lineEdit()->setPlaceholderText(tr("Username"));
m_ui->m_txtPassword->lineEdit()->setPlaceholderText(tr("Password"));
}
void FormEditFeed::loadFeed(TtRssFeed *input_feed) {
m_loadedFeed = input_feed;
setWindowTitle(tr("Edit existing feed"));
// Tiny Tiny RSS does not support editing of these features.
// User can edit only individual auto-update statuses.
m_ui->m_gbAuthentication->setEnabled(false);
m_ui->m_txtUrl->setEnabled(false);
m_ui->m_lblUrl->setEnabled(false);
m_ui->m_lblParentCategory->setEnabled(false);
m_ui->m_cmbParentCategory->setEnabled(false);
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());
}
void FormEditFeed::saveFeed() {
// User edited auto-update status. Save it.
TtRssFeed *new_feed_data = new TtRssFeed();
new_feed_data->setAutoUpdateType(static_cast<Feed::AutoUpdateType>(m_ui->m_cmbAutoUpdateType->itemData(m_ui->m_cmbAutoUpdateType->currentIndex()).toInt()));
new_feed_data->setAutoUpdateInitialInterval(m_ui->m_spinAutoUpdateInterval->value());
m_loadedFeed->editItself(new_feed_data);
delete new_feed_data;
}
void FormEditFeed::loadCategories(const QList<Category*> categories, RootItem *root_item) {
m_ui->m_cmbParentCategory->addItem(root_item->icon(),
root_item->title(),
QVariant::fromValue((void*) root_item));
foreach (Category *category, categories) {
m_ui->m_cmbParentCategory->addItem(category->icon(),
category->title(),
QVariant::fromValue((void*) category));
}
}

View File

@ -0,0 +1,64 @@
// This file is part of RSS Guard.
//
// Copyright (C) 2011-2015 by Martin Rotter <rotter.martinos@gmail.com>
//
// RSS Guard 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 3 of the License, or
// (at your option) any later version.
//
// RSS Guard 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 RSS Guard. If not, see <http://www.gnu.org/licenses/>.
#ifndef FORMEDITFEED_H
#define FORMEDITFEED_H
#include <QDialog>
#include "ui_formeditfeed.h"
namespace Ui {
class FormEditFeed;
}
class TtRssServiceRoot;
class TtRssFeed;
class Category;
class RootItem;
class FormEditFeed : public QDialog {
Q_OBJECT
public:
explicit FormEditFeed(TtRssServiceRoot *root, QWidget *parent = 0);
virtual ~FormEditFeed();
int execForEdit(TtRssFeed *input_feed);
int execForAdd();
private slots:
void performAction();
void onAuthenticationSwitched();
void onAutoUpdateTypeChanged(int new_index);
void onUrlChanged(const QString &new_url);
void onUsernameChanged(const QString &new_username);
void onPasswordChanged(const QString &new_password);
private:
void initialize();
void loadFeed(TtRssFeed *input_feed);
void saveFeed();
void loadCategories(const QList<Category*> categories, RootItem *root_item);
TtRssServiceRoot *m_root;
TtRssFeed *m_loadedFeed;
Ui::FormEditFeed *m_ui;
};
#endif // FORMEDITFEED_H

View File

@ -0,0 +1,192 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FormEditFeed</class>
<widget class="QDialog" name="FormEditFeed">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>469</width>
<height>235</height>
</rect>
</property>
<property name="windowTitle">
<string>Edit feed</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="m_lblParentCategory">
<property name="text">
<string>Parent category</string>
</property>
<property name="buddy">
<cstring>m_cmbParentCategory</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="m_cmbParentCategory">
<property name="toolTip">
<string>Select parent item for your feed.</string>
</property>
<property name="iconSize">
<size>
<width>12</width>
<height>12</height>
</size>
</property>
<property name="frame">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="m_lblUrl">
<property name="text">
<string>URL</string>
</property>
<property name="buddy">
<cstring>m_txtUrl</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="LineEditWithStatus" name="m_txtUrl" native="true"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Auto-update</string>
</property>
<property name="buddy">
<cstring>m_cmbAutoUpdateType</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QComboBox" name="m_cmbAutoUpdateType">
<property name="toolTip">
<string>Select the auto-update strategy for this feed. Default auto-update strategy means that the feed will be update in time intervals set in application settings.</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="m_spinAutoUpdateInterval">
<property name="enabled">
<bool>false</bool>
</property>
<property name="maximumSize">
<size>
<width>130</width>
<height>16777215</height>
</size>
</property>
<property name="suffix">
<string> minutes</string>
</property>
<property name="minimum">
<number>5</number>
</property>
<property name="maximum">
<number>240</number>
</property>
<property name="value">
<number>15</number>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" 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>
</property>
<property name="title">
<string>Requires authentication</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Username</string>
</property>
<property name="buddy">
<cstring>m_txtUsername</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="LineEditWithStatus" name="m_txtUsername" native="true"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Password</string>
</property>
<property name="buddy">
<cstring>m_txtPassword</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="LineEditWithStatus" name="m_txtPassword" native="true"/>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="m_buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>LineEditWithStatus</class>
<extends>QWidget</extends>
<header>lineeditwithstatus.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>m_buttonBox</sender>
<signal>rejected()</signal>
<receiver>FormEditFeed</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>234</x>
<y>78</y>
</hint>
<hint type="destinationlabel">
<x>234</x>
<y>49</y>
</hint>
</hints>
</connection>
</connections>
</ui>