Work on feed add/edit dialog.
This commit is contained in:
parent
daa1e1ab96
commit
75ea2a6e38
@ -23,6 +23,7 @@
|
|||||||
#define APP_VERSION "@APP_VERSION@"
|
#define APP_VERSION "@APP_VERSION@"
|
||||||
#define APP_USERAGENT QString("@APP_NAME@/@APP_VERSION@ (@APP_URL@) on @CMAKE_SYSTEM@; Webkit/") + qWebKitVersion()
|
#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 USER_AGENT_HTTP_HEADER "User-Agent"
|
||||||
#define TEXT_TITLE_LIMIT 30
|
#define TEXT_TITLE_LIMIT 30
|
||||||
#define MAX_ZOOM_FACTOR 10.0
|
#define MAX_ZOOM_FACTOR 10.0
|
||||||
|
@ -17,19 +17,16 @@ class FeedsModelRootItem;
|
|||||||
class QMenu;
|
class QMenu;
|
||||||
class QAction;
|
class QAction;
|
||||||
|
|
||||||
|
|
||||||
class FormStandardCategoryDetails : public QDialog {
|
class FormStandardCategoryDetails : public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructors and destructors.
|
// Constructors and destructors.
|
||||||
// This constructor is supposed to create new categories.
|
|
||||||
explicit FormStandardCategoryDetails(FeedsModel *model, QWidget *parent = 0);
|
explicit FormStandardCategoryDetails(FeedsModel *model, QWidget *parent = 0);
|
||||||
|
|
||||||
// Destructor.
|
|
||||||
virtual ~FormStandardCategoryDetails();
|
virtual ~FormStandardCategoryDetails();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
// Executes add/edit standard category dialog.
|
||||||
int exec(FeedsModelStandardCategory *input_category);
|
int exec(FeedsModelStandardCategory *input_category);
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
@ -50,7 +47,6 @@ class FormStandardCategoryDetails : public QDialog {
|
|||||||
void createConnections();
|
void createConnections();
|
||||||
|
|
||||||
// Sets the category which will be edited.
|
// Sets the category which will be edited.
|
||||||
// NOTE: This is used for editing categories.
|
|
||||||
void setEditableCategory(FeedsModelStandardCategory *editable_category);
|
void setEditableCategory(FeedsModelStandardCategory *editable_category);
|
||||||
|
|
||||||
// Initializes the dialog.
|
// Initializes the dialog.
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "gui/formstandardfeeddetails.h"
|
#include "gui/formstandardfeeddetails.h"
|
||||||
|
|
||||||
|
#include "core/defs.h"
|
||||||
#include "core/textfactory.h"
|
#include "core/textfactory.h"
|
||||||
#include "core/feedsmodel.h"
|
#include "core/feedsmodel.h"
|
||||||
#include "core/feedsmodelrootitem.h"
|
#include "core/feedsmodelrootitem.h"
|
||||||
@ -15,6 +16,8 @@
|
|||||||
|
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
|
#include <QFileDialog>
|
||||||
|
#include <QMenu>
|
||||||
|
|
||||||
|
|
||||||
FormStandardFeedDetails::FormStandardFeedDetails(FeedsModel *model, QWidget *parent)
|
FormStandardFeedDetails::FormStandardFeedDetails(FeedsModel *model, QWidget *parent)
|
||||||
@ -27,6 +30,7 @@ FormStandardFeedDetails::FormStandardFeedDetails(FeedsModel *model, QWidget *par
|
|||||||
// Initialize that shit.
|
// Initialize that shit.
|
||||||
onTitleChanged(QString());
|
onTitleChanged(QString());
|
||||||
onDescriptionChanged(QString());
|
onDescriptionChanged(QString());
|
||||||
|
onUrlChanged(QString());
|
||||||
}
|
}
|
||||||
|
|
||||||
FormStandardFeedDetails::~FormStandardFeedDetails() {
|
FormStandardFeedDetails::~FormStandardFeedDetails() {
|
||||||
@ -42,6 +46,10 @@ int FormStandardFeedDetails::exec(FeedsModelStandardFeed *input_feed) {
|
|||||||
if (input_feed == NULL) {
|
if (input_feed == NULL) {
|
||||||
// User is adding new category.
|
// User is adding new category.
|
||||||
setWindowTitle(tr("Add new standard feed"));
|
setWindowTitle(tr("Add new standard feed"));
|
||||||
|
|
||||||
|
// Make sure that "default" icon is used as the default option for new
|
||||||
|
// feed.
|
||||||
|
m_actionUseDefaultIcon->trigger();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// User is editing existing category.
|
// User is editing existing category.
|
||||||
@ -55,13 +63,13 @@ int FormStandardFeedDetails::exec(FeedsModelStandardFeed *input_feed) {
|
|||||||
|
|
||||||
void FormStandardFeedDetails::onTitleChanged(const QString &new_title){
|
void FormStandardFeedDetails::onTitleChanged(const QString &new_title){
|
||||||
if (new_title.simplified().size() >= MIN_CATEGORY_NAME_LENGTH) {
|
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."));
|
m_ui->m_txtTitle->setStatus(LineEditWithStatus::Ok, tr("Feed name is ok."));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
m_ui->m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
|
||||||
m_ui->m_txtTitle->setStatus(LineEditWithStatus::Error, tr("Feed name is too short."));
|
m_ui->m_txtTitle->setStatus(LineEditWithStatus::Error, tr("Feed name is too short."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkOkButtonEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormStandardFeedDetails::onDescriptionChanged(const QString &new_description) {
|
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) {
|
void FormStandardFeedDetails::onUrlChanged(const QString &new_url) {
|
||||||
if (new_url.isEmpty()) {
|
if (QRegExp(URL_REGEXP).exactMatch(new_url)) {
|
||||||
// New url is well-formed.
|
// New url is well-formed.
|
||||||
|
m_ui->m_txtUrl->setStatus(LineEditWithStatus::Ok, tr("The url is ok."));
|
||||||
}
|
}
|
||||||
else if (!new_url.simplified().isEmpty()) {
|
else if (!new_url.simplified().isEmpty()) {
|
||||||
// New url is not well-formed but is not empty on the other hand.
|
// 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 {
|
else {
|
||||||
// New url is empty.
|
// 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() {
|
void FormStandardFeedDetails::createConnections() {
|
||||||
@ -95,6 +143,9 @@ void FormStandardFeedDetails::createConnections() {
|
|||||||
this, SLOT(onUrlChanged(QString)));
|
this, SLOT(onUrlChanged(QString)));
|
||||||
|
|
||||||
// Icon connections.
|
// 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) {
|
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()->setPlaceholderText(tr("Feed description"));
|
||||||
m_ui->m_txtDescription->lineEdit()->setToolTip(tr("Set description for your feed."));
|
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."));
|
m_ui->m_txtUrl->lineEdit()->setToolTip(tr("Set url for your feed."));
|
||||||
|
|
||||||
#if !defined(Q_OS_WIN)
|
#if !defined(Q_OS_WIN)
|
||||||
@ -148,8 +199,25 @@ void FormStandardFeedDetails::initialize() {
|
|||||||
encoded_encodings.append(encoding);
|
encoded_encodings.append(encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sort encodings and add them.
|
||||||
qSort(encoded_encodings.begin(), encoded_encodings.end(), TextFactory::isCaseInsensitiveLessThan);
|
qSort(encoded_encodings.begin(), encoded_encodings.end(), TextFactory::isCaseInsensitiveLessThan);
|
||||||
m_ui->m_cmbEncoding->addItems(encoded_encodings);
|
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<FeedsModelCategory*> categories,
|
void FormStandardFeedDetails::loadCategories(const QList<FeedsModelCategory*> categories,
|
||||||
|
@ -24,17 +24,30 @@ class FormStandardFeedDetails : public QDialog {
|
|||||||
virtual ~FormStandardFeedDetails();
|
virtual ~FormStandardFeedDetails();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
// Executes add/edit standard feed dialog.
|
||||||
int exec(FeedsModelStandardFeed *input_feed);
|
int exec(FeedsModelStandardFeed *input_feed);
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
// Trigerred when title/description changes.
|
// Trigerred when title/description/url changes.
|
||||||
void onTitleChanged(const QString &new_title);
|
void onTitleChanged(const QString &new_title);
|
||||||
void onDescriptionChanged(const QString &new_description);
|
void onDescriptionChanged(const QString &new_description);
|
||||||
void onUrlChanged(const QString &new_url);
|
void onUrlChanged(const QString &new_url);
|
||||||
|
|
||||||
|
void checkOkButtonEnabled();
|
||||||
|
|
||||||
|
// Icon selectors.
|
||||||
|
void onNoIconSelected();
|
||||||
|
void onLoadIconFromFile();
|
||||||
|
void onUseDefaultIcon();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
// Creates needed connections.
|
||||||
void createConnections();
|
void createConnections();
|
||||||
|
|
||||||
|
// Sets the feed which will be edited.
|
||||||
void setEditableFeed(FeedsModelStandardFeed *editable_feed);
|
void setEditableFeed(FeedsModelStandardFeed *editable_feed);
|
||||||
|
|
||||||
|
// Initializes the dialog.
|
||||||
void initialize();
|
void initialize();
|
||||||
|
|
||||||
// Loads categories into the dialog from the model.
|
// Loads categories into the dialog from the model.
|
||||||
|
@ -13,7 +13,6 @@ LineEditWithStatus::LineEditWithStatus(QWidget *parent)
|
|||||||
m_txtInput = new BaseLineEdit(this);
|
m_txtInput = new BaseLineEdit(this);
|
||||||
m_btnStatus = new PlainToolButton(this);
|
m_btnStatus = new PlainToolButton(this);
|
||||||
|
|
||||||
// TODO: nastavit korektni ikony
|
|
||||||
m_iconInformation = IconThemeFactory::instance()->fromTheme("help-about");
|
m_iconInformation = IconThemeFactory::instance()->fromTheme("help-about");
|
||||||
m_iconWarning = IconThemeFactory::instance()->fromTheme("dialog-warning");
|
m_iconWarning = IconThemeFactory::instance()->fromTheme("dialog-warning");
|
||||||
m_iconError = IconThemeFactory::instance()->fromTheme("dialog-error");
|
m_iconError = IconThemeFactory::instance()->fromTheme("dialog-error");
|
||||||
@ -37,6 +36,8 @@ LineEditWithStatus::~LineEditWithStatus() {
|
|||||||
|
|
||||||
void LineEditWithStatus::setStatus(LineEditWithStatus::StatusType status,
|
void LineEditWithStatus::setStatus(LineEditWithStatus::StatusType status,
|
||||||
const QString &tooltip_text) {
|
const QString &tooltip_text) {
|
||||||
|
m_status = status;
|
||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case Information:
|
case Information:
|
||||||
m_btnStatus->setIcon(m_iconInformation);
|
m_btnStatus->setIcon(m_iconInformation);
|
||||||
|
@ -33,12 +33,17 @@ class LineEditWithStatus : public QWidget {
|
|||||||
// Sets custom status for this control.
|
// Sets custom status for this control.
|
||||||
void setStatus(StatusType status, const QString &tooltip_text);
|
void setStatus(StatusType status, const QString &tooltip_text);
|
||||||
|
|
||||||
|
inline StatusType status() const {
|
||||||
|
return m_status;
|
||||||
|
}
|
||||||
|
|
||||||
// Access to line edit.
|
// Access to line edit.
|
||||||
inline BaseLineEdit *lineEdit() const {
|
inline BaseLineEdit *lineEdit() const {
|
||||||
return m_txtInput;
|
return m_txtInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
StatusType m_status;
|
||||||
BaseLineEdit *m_txtInput;
|
BaseLineEdit *m_txtInput;
|
||||||
PlainToolButton *m_btnStatus;
|
PlainToolButton *m_btnStatus;
|
||||||
QHBoxLayout *m_layout;
|
QHBoxLayout *m_layout;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user