diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6de34db..3391603 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,132 +1,132 @@ add_subdirectory(noteshared) add_subdirectory(kontact_plugin) add_definitions(-DTRANSLATION_DOMAIN=\"kjots\") configure_file(kjots-version.h.in ${CMAKE_CURRENT_BINARY_DIR}/kjots-version.h @ONLY ) ######################################################################### # Code common to the kjots application and the kontact plugin # Don't make it a static library, this code needs to be compiled # with -fPIC for the part and without -fPIC for the executable ######################################################################### set(kjots_config_SRCS kjotsconfigdlg.cpp) kconfig_add_kcfg_files(kjots_config_SRCS KJotsSettings.kcfgc ) ki18n_wrap_ui(kjots_config_SRCS confpagemisc.ui) set(kjots_common_SRCS aboutdata.cpp kjotsedit.cpp kjotsbookmarks.cpp kjotsmodel.cpp kjotssortproxymodel.cpp kjotswidget.cpp kjotsbrowser.cpp kjotslinkdialog.cpp - kjotsbookshelfentryvalidator.cpp ${kjots_config_SRCS} ) +ki18n_wrap_ui(kjots_common_SRCS linkdialog.ui) add_library(kjots_common STATIC ${kjots_common_SRCS}) target_link_libraries(kjots_common noteshared Qt5::DBus Qt5::PrintSupport KF5::KCMUtils KF5::Bookmarks KF5::ConfigWidgets KF5::TextWidgets KF5::Mime KF5::AkonadiCore KF5::AkonadiWidgets KF5::PimTextEdit KF5::XmlGui KF5::KIOWidgets Grantlee5::Templates Grantlee5::TextDocument ) ######################################################################### # D-Bus interface ######################################################################### qt5_generate_dbus_interface( kjotswidget.h org.kde.KJotsWidget.xml OPTIONS -m ) qt5_add_dbus_interfaces(kjots_common_SRCS ${CMAKE_CURRENT_BINARY_DIR}/org.kde.KJotsWidget.xml) ######################################################################### # Main Application SECTION ######################################################################### set(kjots_SRCS main.cpp KJotsMain.cpp ) file(GLOB ICONS_SRCS "${CMAKE_SOURCE_DIR}/icons/*-apps-kjots.png") ecm_add_app_icon(kjots_SRCS ICONS ${ICONS_SRCS}) add_executable(kjots ${kjots_SRCS}) target_link_libraries(kjots kjots_common KF5::KontactInterface ) install(TARGETS kjots ${INSTALL_TARGETS_DEFAULT_ARGS}) install(FILES kjots.kcfg DESTINATION ${KCFG_INSTALL_DIR} ) install(FILES kjotsui.rc DESTINATION ${KXMLGUI_INSTALL_DIR}/kjots ) ############## next target ############## set(kjotspart_PART_SRCS kjotspart.cpp ) add_library(kjotspart MODULE ${kjotspart_PART_SRCS}) target_link_libraries(kjotspart kjots_common KF5::Parts ) install(FILES ${CMAKE_SOURCE_DIR}/data/kjotspart.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) install(TARGETS kjotspart DESTINATION ${PLUGIN_INSTALL_DIR} ) ########################################################################### set(kcm_kjots_PART_SRCS kcm_kjots.cpp ${kjots_config_SRCS} ) add_library(kcm_kjots MODULE ${kcm_kjots_PART_SRCS}) target_link_libraries(kcm_kjots KF5::KCMUtils KF5::I18n ) install(TARGETS kcm_kjots DESTINATION ${PLUGIN_INSTALL_DIR} ) install(FILES ${CMAKE_SOURCE_DIR}/data/kjots_config_misc.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) diff --git a/src/kjotsbookshelfentryvalidator.cpp b/src/kjotsbookshelfentryvalidator.cpp deleted file mode 100644 index f62fb84..0000000 --- a/src/kjotsbookshelfentryvalidator.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - This file is part of KJots. - - Copyright (c) 2008 Stephen Kelly - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library 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 Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "kjotsbookshelfentryvalidator.h" - -#include - -KJotsBookshelfEntryValidator::KJotsBookshelfEntryValidator(QAbstractItemModel *model, QObject *parent) - : QValidator(parent) -{ - m_model = model; -} - -QValidator::State KJotsBookshelfEntryValidator::validate(QString &input, int &pos) const -{ - Q_UNUSED(pos) - if (!m_model) { - return Invalid; - } - if (input.isEmpty()) { - return Intermediate; - } - - const QModelIndexList list = m_model->match( - m_model->index(0, 0), - Qt::DisplayRole, - input, - Qt::MatchStartsWith | Qt::MatchFixedString | Qt::MatchWrap); - - if (list.empty()) { - return Invalid; - } - - if (std::any_of(list.cbegin(), list.cend(), [&input](const QModelIndex &index) { - return QString::compare(index.data().toString(), input, Qt::CaseInsensitive); - })) { - return Acceptable; - } else { - return Intermediate; - } -} - diff --git a/src/kjotsbookshelfentryvalidator.h b/src/kjotsbookshelfentryvalidator.h deleted file mode 100644 index db367eb..0000000 --- a/src/kjotsbookshelfentryvalidator.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - This file is part of KJots. - - Copyright (c) 2008 Stephen Kelly - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library 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 Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef KJOTSBOOKSHELFENTRYVALIDATOR -#define KJOTSBOOKSHELFENTRYVALIDATOR - -#include - -class QAbstractItemModel; - -/** - This class is a validator intended to be used with an editable QComboBox. - - \a validate returns the state of whether the text in the lineedit matches one of the items in the - model. All matching is attempted on the first column of the model. - -*/ -class KJotsBookshelfEntryValidator : public QValidator -{ - Q_OBJECT -public: - /** - Create a new Validator for Entries in the KJots bookshelf. - @param parent The parent object. - @param model The model to use to validate the input. - */ - explicit KJotsBookshelfEntryValidator(QAbstractItemModel *model, QObject *parent = nullptr); - - /** - Returns the state of whether \p input matches one of the items in the model. - - If the text does not match any item in the model, the state is Invalid. - If the text is empty, the state is Intermediate. - If the text matches the start of one or more items in the model, the state is Intermediate. - If the text matches one of the items in the model exactly, the state is Acceptable. - - \return The validation state. - */ - QValidator::State validate(QString &input, int &pos) const override; - -private: - QAbstractItemModel *m_model; - -}; - -#endif diff --git a/src/kjotslinkdialog.cpp b/src/kjotslinkdialog.cpp index 6b4b06d..830271c 100644 --- a/src/kjotslinkdialog.cpp +++ b/src/kjotslinkdialog.cpp @@ -1,164 +1,89 @@ /* kjots Copyright (C) 2008 Stephen Kelly This program 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 2 of the License, or (at your option) any later version. This program 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 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kjotslinkdialog.h" +#include "ui_linkdialog.h" +#include "kjotsmodel.h" -#include -#include -#include -#include -#include -#include +#include #include -#include -#include -#include +#include #include -#include -#include "KJotsSettings.h" -#include "kjotsbookshelfentryvalidator.h" -#include "kjotsmodel.h" KJotsLinkDialog::KJotsLinkDialog(QAbstractItemModel *kjotsModel, QWidget *parent) - : QDialog(parent), m_kjotsModel(kjotsModel) + : QDialog(parent) + , ui(new Ui::LinkDialog) { - setWindowTitle(i18n("Manage Link")); - auto *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); - auto *mainLayout = new QVBoxLayout(this); - setLayout(mainLayout); - QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); - okButton->setDefault(true); - okButton->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Return)); - connect(buttonBox, &QDialogButtonBox::accepted, this, &KJotsLinkDialog::accept); - connect(buttonBox, &QDialogButtonBox::rejected, this, &KJotsLinkDialog::reject); - okButton->setDefault(true); - setModal(true); - - auto *proxyModel = new KDescendantsProxyModel(this); - proxyModel->setSourceModel(kjotsModel); - proxyModel->setAncestorSeparator(QStringLiteral(" / ")); - - m_descendantsProxyModel = proxyModel; - - auto *entries = new QWidget(this); - - auto *layout = new QGridLayout(entries); - - textLabel = new QLabel(i18n("Link Text:"), this); - textLineEdit = new QLineEdit(this); - textLineEdit->setClearButtonEnabled(true); - linkUrlLabel = new QLabel(i18n("Link URL:"), this); - linkUrlLineEdit = new QLineEdit(this); - hrefCombo = new QComboBox(this); - linkUrlLineEdit->setClearButtonEnabled(true); - - tree = new QTreeView(this); - tree->setModel(proxyModel); - tree->expandAll(); - tree->setColumnHidden(1, true); - hrefCombo->setModel(proxyModel); - hrefCombo->setView(tree); - - hrefCombo->setEditable(true); - auto *completer = new QCompleter(proxyModel, this); + ui->setupUi(this); + + m_descendantsProxyModel = new KDescendantsProxyModel(this); + m_descendantsProxyModel->setSourceModel(kjotsModel); + m_descendantsProxyModel->setAncestorSeparator(QStringLiteral(" / ")); + m_descendantsProxyModel->setDisplayAncestorData(true); + + ui->hrefCombo->lineEdit()->setPlaceholderText(i18n("Enter link URL, or another note or note book...")); + ui->hrefCombo->setModel(m_descendantsProxyModel); + // This is required because otherwise QComboBox will catch Enter, insert a new item and clear + ui->hrefCombo->setInsertPolicy(QComboBox::NoInsert); + ui->hrefCombo->setCurrentIndex(-1); + + auto *completer = new QCompleter(m_descendantsProxyModel, this); completer->setCaseSensitivity(Qt::CaseInsensitive); - hrefCombo->setCompleter(completer); - auto *validator = new KJotsBookshelfEntryValidator(proxyModel, this); - hrefCombo->setValidator(validator); - - auto *linkLayout = new QGridLayout(this); - linkUrlLineEditRadioButton = new QRadioButton(entries); - hrefComboRadioButton = new QRadioButton(entries); - - connect(linkUrlLineEditRadioButton, &QRadioButton::toggled, linkUrlLineEdit, &QLineEdit::setEnabled); - connect(hrefComboRadioButton, &QRadioButton::toggled, hrefCombo, &QComboBox::setEnabled); - hrefCombo->setEnabled(false); - linkUrlLineEditRadioButton->setChecked(true); - - linkLayout->addWidget(linkUrlLineEditRadioButton, 0, 0); - linkLayout->addWidget(linkUrlLineEdit, 0, 1); - linkLayout->addWidget(hrefComboRadioButton, 1, 0); - linkLayout->addWidget(hrefCombo, 1, 1); - - layout->addWidget(textLabel, 0, 0); - layout->addWidget(textLineEdit, 0, 1); - layout->addWidget(linkUrlLabel, 1, 0); - layout->addLayout(linkLayout, 1, 1); - - mainLayout->addWidget(entries); - mainLayout->addWidget(buttonBox); - textLineEdit->setFocus(); - - connect(hrefCombo, &QComboBox::editTextChanged, this, &KJotsLinkDialog::trySetEntry); + ui->hrefCombo->setCompleter(completer); } +KJotsLinkDialog::~KJotsLinkDialog() = default; + void KJotsLinkDialog::setLinkText(const QString &linkText) { - textLineEdit->setText(linkText); - if (!linkText.trimmed().isEmpty()) { - linkUrlLineEdit->setFocus(); + ui->textEdit->setText(linkText); + if (!linkText.isEmpty()) { + ui->textEdit->setFocus(); } } void KJotsLinkDialog::setLinkUrl(const QString &linkUrl) { - const QUrl url(linkUrl); - if (url.scheme() == QStringLiteral("akonadi")) { - QModelIndex idx = KJotsModel::modelIndexForUrl(m_descendantsProxyModel, url); - if (idx.isValid()) { - hrefComboRadioButton->setChecked(true); - hrefCombo->view()->setCurrentIndex(idx); - hrefCombo->setCurrentIndex(idx.row()); - } + const QModelIndex idx = KJotsModel::modelIndexForUrl(m_descendantsProxyModel, QUrl(linkUrl)); + if (idx.isValid()) { + ui->hrefCombo->setCurrentIndex(idx.row()); } else { - linkUrlLineEdit->setText(linkUrl); - linkUrlLineEditRadioButton->setChecked(true); - return; + ui->hrefCombo->setCurrentIndex(-1); + ui->hrefCombo->setCurrentText(linkUrl); } } QString KJotsLinkDialog::linkText() const { - return textLineEdit->text().trimmed(); -} - -void KJotsLinkDialog::trySetEntry(const QString &text) -{ - QString t(text); - int pos = hrefCombo->lineEdit()->cursorPosition(); - if (hrefCombo->validator()->validate(t, pos) == KJotsBookshelfEntryValidator::Acceptable) { - int row = hrefCombo->findText(t, Qt::MatchFixedString); - QModelIndex index = hrefCombo->model()->index(row, 0); - hrefCombo->view()->setCurrentIndex(index); - hrefCombo->setCurrentIndex(row); - } + return ui->textEdit->text().trimmed(); } QString KJotsLinkDialog::linkUrl() const { - if (hrefComboRadioButton->isChecked()) { - return hrefCombo->view()->currentIndex().data(KJotsModel::EntityUrlRole).toString(); + const int row = ui->hrefCombo->currentIndex(); + if (row != -1) { + return ui->hrefCombo->model()->index(row, 0).data(KJotsModel::EntityUrlRole).toString(); } else { - return linkUrlLineEdit->text(); + return ui->hrefCombo->currentText().trimmed(); } } diff --git a/src/kjotslinkdialog.h b/src/kjotslinkdialog.h index 4c7a0a8..69ee2f3 100644 --- a/src/kjotslinkdialog.h +++ b/src/kjotslinkdialog.h @@ -1,81 +1,73 @@ /* kjots Copyright (C) 2008 Stephen Kelly This program 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 2 of the License, or (at your option) any later version. This program 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 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KJOTSLINKDIALOG_H #define KJOTSLINKDIALOG_H #include -class QLabel; +namespace Ui { + class LinkDialog; +} + +class QListView; + +class KDescendantsProxyModel; + class QAbstractItemModel; class QString; -class QRadioButton; -class QTreeView; -class QComboBox; -class QLineEdit; class KJotsLinkDialog : public QDialog { Q_OBJECT public: explicit KJotsLinkDialog(QAbstractItemModel *kjotsModel, QWidget *parent = nullptr); + ~KJotsLinkDialog(); /** * Returns the link text shown in the dialog * @param linkText The initial text */ void setLinkText(const QString &linkText); /** * Sets the target link url shown in the dialog * @param linkUrl The initial link target url */ void setLinkUrl(const QString &linkUrl); /** * Returns the link text entered by the user. * @return The link text */ QString linkText() const; /** * Returns the target link url entered by the user. * @return The link url */ QString linkUrl() const; - -public Q_SLOTS: - void trySetEntry(const QString &text); - private: - QLabel *textLabel; - QLineEdit *textLineEdit; - QLabel *linkUrlLabel; - QLineEdit *linkUrlLineEdit; - QComboBox *hrefCombo; - QRadioButton *linkUrlLineEditRadioButton; - QRadioButton *hrefComboRadioButton; - QTreeView *tree; - QAbstractItemModel *m_kjotsModel; - QAbstractItemModel *m_descendantsProxyModel; + std::unique_ptr ui; + KDescendantsProxyModel *m_descendantsProxyModel; }; #endif diff --git a/src/linkdialog.ui b/src/linkdialog.ui new file mode 100644 index 0000000..1de512a --- /dev/null +++ b/src/linkdialog.ui @@ -0,0 +1,109 @@ + + + LinkDialog + + + + 0 + 0 + 485 + 127 + + + + Manage Link + + + + .. + + + true + + + + + + + + Link &Text: + + + textEdit + + + + + + + true + + + + + + + Link URL: + + + + + + + true + + + QComboBox::NoInsert + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + LinkDialog + accept() + + + 224 + 197 + + + 157 + 223 + + + + + buttonBox + rejected() + LinkDialog + reject() + + + 292 + 203 + + + 286 + 223 + + + + +