From 75ea2a6e38487c7ccc3df6df3898beffa9f393b7 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Thu, 30 Jan 2014 08:31:55 +0100 Subject: [PATCH] Work on feed add/edit dialog. --- src/core/defs.h.in | 1 + src/gui/formstandardcategorydetails.h | 6 +-- src/gui/formstandardfeeddetails.cpp | 76 +++++++++++++++++++++++++-- src/gui/formstandardfeeddetails.h | 15 +++++- src/gui/lineeditwithstatus.cpp | 3 +- src/gui/lineeditwithstatus.h | 5 ++ 6 files changed, 95 insertions(+), 11 deletions(-) diff --git a/src/core/defs.h.in b/src/core/defs.h.in index 98b79085f..dc7084400 100755 --- a/src/core/defs.h.in +++ b/src/core/defs.h.in @@ -23,6 +23,7 @@ #define APP_VERSION "@APP_VERSION@" #define APP_USERAGENT QString("@APP_NAME@/@APP_VERSION@ (@APP_URL@) on @CMAKE_SYSTEM@; Webkit/") + qWebKitVersion() +#define URL_REGEXP "^(http|https|feed|ftp):\\/\\/[\\w\\-_]+(\\.[\\w\\-_]+)+([\\w\\-\\.,@?^=%&:/~\\+#]*[\\w\\-\\@?^=%&/~\\+#])?$" #define USER_AGENT_HTTP_HEADER "User-Agent" #define TEXT_TITLE_LIMIT 30 #define MAX_ZOOM_FACTOR 10.0 diff --git a/src/gui/formstandardcategorydetails.h b/src/gui/formstandardcategorydetails.h index e335394c9..ce9ddce36 100644 --- a/src/gui/formstandardcategorydetails.h +++ b/src/gui/formstandardcategorydetails.h @@ -17,19 +17,16 @@ class FeedsModelRootItem; class QMenu; class QAction; - class FormStandardCategoryDetails : public QDialog { Q_OBJECT public: // Constructors and destructors. - // This constructor is supposed to create new categories. explicit FormStandardCategoryDetails(FeedsModel *model, QWidget *parent = 0); - - // Destructor. virtual ~FormStandardCategoryDetails(); public slots: + // Executes add/edit standard category dialog. int exec(FeedsModelStandardCategory *input_category); protected slots: @@ -50,7 +47,6 @@ class FormStandardCategoryDetails : public QDialog { void createConnections(); // Sets the category which will be edited. - // NOTE: This is used for editing categories. void setEditableCategory(FeedsModelStandardCategory *editable_category); // Initializes the dialog. diff --git a/src/gui/formstandardfeeddetails.cpp b/src/gui/formstandardfeeddetails.cpp index 5c6c2f416..bbb5fd1d2 100644 --- a/src/gui/formstandardfeeddetails.cpp +++ b/src/gui/formstandardfeeddetails.cpp @@ -1,5 +1,6 @@ #include "gui/formstandardfeeddetails.h" +#include "core/defs.h" #include "core/textfactory.h" #include "core/feedsmodel.h" #include "core/feedsmodelrootitem.h" @@ -15,6 +16,8 @@ #include #include +#include +#include FormStandardFeedDetails::FormStandardFeedDetails(FeedsModel *model, QWidget *parent) @@ -27,6 +30,7 @@ FormStandardFeedDetails::FormStandardFeedDetails(FeedsModel *model, QWidget *par // Initialize that shit. onTitleChanged(QString()); onDescriptionChanged(QString()); + onUrlChanged(QString()); } FormStandardFeedDetails::~FormStandardFeedDetails() { @@ -42,6 +46,10 @@ int FormStandardFeedDetails::exec(FeedsModelStandardFeed *input_feed) { if (input_feed == NULL) { // User is adding new category. setWindowTitle(tr("Add new standard feed")); + + // Make sure that "default" icon is used as the default option for new + // feed. + m_actionUseDefaultIcon->trigger(); } else { // User is editing existing category. @@ -55,13 +63,13 @@ int FormStandardFeedDetails::exec(FeedsModelStandardFeed *input_feed) { void FormStandardFeedDetails::onTitleChanged(const QString &new_title){ if (new_title.simplified().size() >= MIN_CATEGORY_NAME_LENGTH) { - m_ui->m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); m_ui->m_txtTitle->setStatus(LineEditWithStatus::Ok, tr("Feed name is ok.")); } else { - m_ui->m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); m_ui->m_txtTitle->setStatus(LineEditWithStatus::Error, tr("Feed name is too short.")); } + + checkOkButtonEnabled(); } void FormStandardFeedDetails::onDescriptionChanged(const QString &new_description) { @@ -74,15 +82,55 @@ void FormStandardFeedDetails::onDescriptionChanged(const QString &new_descriptio } void FormStandardFeedDetails::onUrlChanged(const QString &new_url) { - if (new_url.isEmpty()) { + 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.simplified().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.")); } + + checkOkButtonEnabled(); +} + +void FormStandardFeedDetails::checkOkButtonEnabled() { + LineEditWithStatus::StatusType title_status = m_ui->m_txtTitle->status(); + LineEditWithStatus::StatusType url_status = m_ui->m_txtUrl->status(); + + m_ui->m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(title_status == LineEditWithStatus::Ok && + (url_status == LineEditWithStatus::Ok || + url_status == LineEditWithStatus::Warning)); +} + +void FormStandardFeedDetails::onNoIconSelected() { + m_ui->m_btnIcon->setIcon(QIcon()); +} + +void FormStandardFeedDetails::onLoadIconFromFile() { + QFileDialog dialog(this, tr("Select icon file for the feed"), + QDir::homePath(), tr("Images (*.bmp *.jpg *.jpeg *.png *.svg *.tga)")); + dialog.setFileMode(QFileDialog::ExistingFile); + dialog.setWindowIcon(IconThemeFactory::instance()->fromTheme("image-x-generic")); + dialog.setOptions(QFileDialog::DontUseNativeDialog | QFileDialog::ReadOnly); + dialog.setViewMode(QFileDialog::Detail); + dialog.setLabelText(QFileDialog::Accept, tr("Select icon")); + dialog.setLabelText(QFileDialog::Reject, tr("Cancel")); + dialog.setLabelText(QFileDialog::LookIn, tr("Look in:")); + dialog.setLabelText(QFileDialog::FileName, tr("Icon name:")); + dialog.setLabelText(QFileDialog::FileType, tr("Icon type:")); + + if (dialog.exec() == QDialog::Accepted) { + m_ui->m_btnIcon->setIcon(QIcon(dialog.selectedFiles().value(0))); + } +} + +void FormStandardFeedDetails::onUseDefaultIcon() { + m_ui->m_btnIcon->setIcon(IconThemeFactory::instance()->fromTheme("application-rss+xml")); } void FormStandardFeedDetails::createConnections() { @@ -95,6 +143,9 @@ void FormStandardFeedDetails::createConnections() { this, SLOT(onUrlChanged(QString))); // Icon connections. + connect(m_actionLoadIconFromFile, SIGNAL(triggered()), this, SLOT(onLoadIconFromFile())); + connect(m_actionNoIcon, SIGNAL(triggered()), this, SLOT(onNoIconSelected())); + connect(m_actionUseDefaultIcon, SIGNAL(triggered()), this, SLOT(onUseDefaultIcon())); } void FormStandardFeedDetails::setEditableFeed(FeedsModelStandardFeed *editable_feed) { @@ -127,7 +178,7 @@ void FormStandardFeedDetails::initialize() { m_ui->m_txtDescription->lineEdit()->setPlaceholderText(tr("Feed description")); m_ui->m_txtDescription->lineEdit()->setToolTip(tr("Set description for your feed.")); - m_ui->m_txtUrl->lineEdit()->setPlaceholderText(tr("Feed url")); + m_ui->m_txtUrl->lineEdit()->setPlaceholderText(tr("Full feed url including scheme")); m_ui->m_txtUrl->lineEdit()->setToolTip(tr("Set url for your feed.")); #if !defined(Q_OS_WIN) @@ -148,8 +199,25 @@ void FormStandardFeedDetails::initialize() { encoded_encodings.append(encoding); } + // Sort encodings and add them. qSort(encoded_encodings.begin(), encoded_encodings.end(), TextFactory::isCaseInsensitiveLessThan); m_ui->m_cmbEncoding->addItems(encoded_encodings); + + // Setup menu & actions for icon selection. + m_iconMenu = new QMenu(tr("Icon selection"), this); + m_actionLoadIconFromFile = new QAction(IconThemeFactory::instance()->fromTheme("image-x-generic"), + tr("Load icon from file..."), + this); + m_actionNoIcon = new QAction(IconThemeFactory::instance()->fromTheme("edit-delete"), + tr("Do not use icon"), + this); + m_actionUseDefaultIcon = new QAction(IconThemeFactory::instance()->fromTheme("application-rss+xml"), + tr("Use default icon"), + this); + m_iconMenu->addAction(m_actionLoadIconFromFile); + m_iconMenu->addAction(m_actionUseDefaultIcon); + m_iconMenu->addAction(m_actionNoIcon); + m_ui->m_btnIcon->setMenu(m_iconMenu); } void FormStandardFeedDetails::loadCategories(const QList categories, diff --git a/src/gui/formstandardfeeddetails.h b/src/gui/formstandardfeeddetails.h index f906d2fe1..7ff1aa4ab 100644 --- a/src/gui/formstandardfeeddetails.h +++ b/src/gui/formstandardfeeddetails.h @@ -24,17 +24,30 @@ class FormStandardFeedDetails : public QDialog { virtual ~FormStandardFeedDetails(); public slots: + // Executes add/edit standard feed dialog. int exec(FeedsModelStandardFeed *input_feed); protected slots: - // Trigerred when title/description changes. + // Trigerred when title/description/url changes. void onTitleChanged(const QString &new_title); void onDescriptionChanged(const QString &new_description); void onUrlChanged(const QString &new_url); + void checkOkButtonEnabled(); + + // Icon selectors. + void onNoIconSelected(); + void onLoadIconFromFile(); + void onUseDefaultIcon(); + protected: + // Creates needed connections. void createConnections(); + + // Sets the feed which will be edited. void setEditableFeed(FeedsModelStandardFeed *editable_feed); + + // Initializes the dialog. void initialize(); // Loads categories into the dialog from the model. diff --git a/src/gui/lineeditwithstatus.cpp b/src/gui/lineeditwithstatus.cpp index 134bc9f26..97e5fb9f9 100644 --- a/src/gui/lineeditwithstatus.cpp +++ b/src/gui/lineeditwithstatus.cpp @@ -13,7 +13,6 @@ LineEditWithStatus::LineEditWithStatus(QWidget *parent) m_txtInput = new BaseLineEdit(this); m_btnStatus = new PlainToolButton(this); - // TODO: nastavit korektni ikony m_iconInformation = IconThemeFactory::instance()->fromTheme("help-about"); m_iconWarning = IconThemeFactory::instance()->fromTheme("dialog-warning"); m_iconError = IconThemeFactory::instance()->fromTheme("dialog-error"); @@ -37,6 +36,8 @@ LineEditWithStatus::~LineEditWithStatus() { void LineEditWithStatus::setStatus(LineEditWithStatus::StatusType status, const QString &tooltip_text) { + m_status = status; + switch (status) { case Information: m_btnStatus->setIcon(m_iconInformation); diff --git a/src/gui/lineeditwithstatus.h b/src/gui/lineeditwithstatus.h index 96bb89aa9..c183cb637 100644 --- a/src/gui/lineeditwithstatus.h +++ b/src/gui/lineeditwithstatus.h @@ -33,12 +33,17 @@ class LineEditWithStatus : public QWidget { // Sets custom status for this control. void setStatus(StatusType status, const QString &tooltip_text); + inline StatusType status() const { + return m_status; + } + // Access to line edit. inline BaseLineEdit *lineEdit() const { return m_txtInput; } private: + StatusType m_status; BaseLineEdit *m_txtInput; PlainToolButton *m_btnStatus; QHBoxLayout *m_layout;