diff --git a/blogilo/src/mainwindow.cpp b/blogilo/src/mainwindow.cpp index 9a0fa49a57..73a0c7d1f6 100644 --- a/blogilo/src/mainwindow.cpp +++ b/blogilo/src/mainwindow.cpp @@ -1,674 +1,674 @@ /* This file is part of Blogilo, A KDE Blogging Client Copyright (C) 2008-2010 Mehrdad Momeny Copyright (C) 2008-2010 Golnaz Nilieh Copyright (C) 2013-2016 Laurent Montel 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) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. 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, see http://www.gnu.org/licenses/ */ #include "mainwindow.h" #include "global.h" #include "dbman.h" #include "toolbox.h" #include "postentry.h" #include "addeditblog.h" #include "backend.h" #include "bilbomedia.h" #include "settings.h" #include "bilboblog.h" #include "blogsettings.h" #include "poststabwidget.h" #include "uploadmediadialog.h" #include "configuredialog.h" #include "ui_advancedsettingsbase.h" #include "ui_settingsbase.h" #include "ui_editorsettingsbase.h" #include "Libkdepim/ProgressDialog" #include #include #include #include #include #include #include #include #include #include #include "blogilo_debug.h" #include #include #include #include #include #include #include #include #include #include #include #define TIMEOUT 5000 MainWindow::MainWindow() : KXmlGuiWindow(), activePost(Q_NULLPTR), systemTray(Q_NULLPTR), previousActivePostIndex(-1), busyNumber(0), progress(Q_NULLPTR), mCurrentBlogId(__currentBlogId) { setWindowTitle(i18n("Blogilo")); tabPosts = new PostsTabWidget(this); setCentralWidget(tabPosts); connect(tabPosts, &PostsTabWidget::createNewPost, this, &MainWindow::slotCreateNewPost); connect(tabPosts, &PostsTabWidget::closeTabClicked, this, &MainWindow::slotCloseTabClicked); connect(tabPosts, &PostsTabWidget::tabCloseRequested, this, &MainWindow::slotRemovePostEntry); connect(tabPosts, &PostsTabWidget::tabRemoveAllExclude, this, &MainWindow::slotRemoveAllExclude); toolbox = new Toolbox(this); toolboxDock = new QDockWidget(i18n("Toolbox"), this); toolboxDock->setAllowedAreas(Qt::RightDockWidgetArea | Qt::LeftDockWidgetArea); toolboxDock->setFeatures(QDockWidget::AllDockWidgetFeatures); toolboxDock->setWidget(toolbox); toolboxDock->setObjectName(QStringLiteral("dock_toolbox")); toolbox->setObjectName(QStringLiteral("toolbox")); this->addDockWidget(Qt::RightDockWidgetArea, toolboxDock); // then, setup our actions setupActions(); setupStatusBar(); // a call to KXmlGuiWindow::setupGUI() populates the GUI // with actions, using KXMLGUI. // It also applies the saved mainwindow settings, if any, and ask the // mainwindow to automatically save settings if changed: window size, // toolbar position, icon size, etc. setupGUI(); toolbox->setVisible(Settings::showToolboxOnStart()); actionCollection()->action(QStringLiteral("toggle_toolbox"))->setChecked(Settings::showToolboxOnStart()); setupSystemTray(); connect(tabPosts, &PostsTabWidget::currentChanged, this, &MainWindow::slotActivePostChanged); connect(toolbox, &Toolbox::sigEntrySelected, this, &MainWindow::slotNewPostOpened); connect(toolbox, &Toolbox::sigError, this, &MainWindow::slotError); connect(toolbox, &Toolbox::sigBusy, this, &MainWindow::slotBusy); foreach (BilboBlog *blog, DBMan::self()->blogList()) { QAction *act = new QAction(blog->title(), blogs); act->setCheckable(true); act->setData(blog->id()); blogs->addAction(act); } connect(blogs, static_cast(&KSelectAction::triggered), this, &MainWindow::currentBlogChanged); - QTimer::singleShot(0, this, SLOT(loadTempPosts())); + QTimer::singleShot(0, this, &MainWindow::loadTempPosts); } MainWindow::~MainWindow() { } void MainWindow::setupStatusBar() { } void MainWindow::slotUploadFileDone(const QString &serviceName, const QString &link) { Q_UNUSED(serviceName); KMessageBox::information(this, i18n("File uploaded. You can access to it at this url %1", link), i18n("Upload File")); } void MainWindow::slotUploadFileFailed(const QString &serviceName, const QString &filename) { Q_UNUSED(serviceName); Q_UNUSED(filename); KMessageBox::error(this, i18n("Error during upload."), i18n("Upload File")); } void MainWindow::slotActionFailed(const QString &serviceName, const QString &error) { KMessageBox::error(this, i18n("%1 return an error '%2'", serviceName, error), i18n("Error")); } void MainWindow::slotCloseTabClicked() { const int currentIndex = tabPosts->currentIndex(); if (currentIndex != -1) { slotRemovePostEntry(currentIndex); } } void MainWindow::closeEvent(QCloseEvent *event) { writeConfigs(); if (!DBMan::self()->clearTempEntries()) { qCDebug(BLOGILO_LOG) << "Could not erase temp_post table: " << DBMan::self()->lastErrorText(); } const int count = tabPosts->count(); if (count > 0) { toolbox->getFieldsValue(activePost->currentPost()); for (int i = 0; i < count; ++i) { PostEntry *pst = qobject_cast(tabPosts->widget(i)); DBMan::self()->saveTempEntry(*pst->currentPost(), pst->currentPostBlogId()); } } event->accept(); } void MainWindow::setupActions() { KStandardAction::quit(qApp, SLOT(quit()), actionCollection()); - KStandardAction::preferences(this, SLOT(optionsPreferences()), actionCollection()); + KStandardAction::preferences(this, &MainWindow::optionsPreferences, actionCollection()); // custom menu and menu item QAction *actNewPost = new QAction(QIcon::fromTheme(QStringLiteral("document-new")), i18n("New Post"), this); actionCollection()->addAction(QStringLiteral("new_post"), actNewPost); actionCollection()->setDefaultShortcut(actNewPost, QKeySequence(Qt::CTRL + Qt::Key_N)); connect(actNewPost, &QAction::triggered, this, &MainWindow::slotCreateNewPost); QAction *actAddBlog = new QAction(QIcon::fromTheme(QStringLiteral("list-add")), i18n("Add Blog..."), this); actionCollection()->addAction(QStringLiteral("add_blog"), actAddBlog); connect(actAddBlog, &QAction::triggered, this, &MainWindow::addBlog); QAction *actPublish = new QAction(QIcon::fromTheme(QStringLiteral("arrow-up")), i18n("Submit..."), this); actionCollection()->addAction(QStringLiteral("publish_post"), actPublish); connect(actPublish, &QAction::triggered, this, &MainWindow::slotPublishPost); QAction *actUpload = new QAction(QIcon::fromTheme(QStringLiteral("upload-media")), i18n("Upload Media..."), this); actionCollection()->addAction(QStringLiteral("upload_media"), actUpload); connect(actUpload, &QAction::triggered, this, &MainWindow::uploadMediaObject); QAction *actSaveLocally = new QAction(QIcon::fromTheme(QStringLiteral("document-save")), i18n("Save Locally"), this); actionCollection()->addAction(QStringLiteral("save_locally"), actSaveLocally); actionCollection()->setDefaultShortcut(actSaveLocally, QKeySequence(Qt::CTRL + Qt::Key_S)); connect(actSaveLocally, &QAction::triggered, this, &MainWindow::slotSavePostLocally); KToggleAction *actToggleToolboxVisible = new KToggleAction(i18n("Show Toolbox"), this); actionCollection()->addAction(QStringLiteral("toggle_toolbox"), actToggleToolboxVisible); actionCollection()->setDefaultShortcut(actToggleToolboxVisible, QKeySequence(Qt::CTRL + Qt::Key_T)); connect(actToggleToolboxVisible, &KToggleAction::toggled, this, &MainWindow::slotToggleToolboxVisible); connect(toolboxDock, &QDockWidget::visibilityChanged, this, &MainWindow::slotToolboxVisibilityChanged); blogs = new KSelectAction(this); actionCollection()->addAction(QStringLiteral("blogs_list"), blogs); QAction *actOpenBlog = new QAction(QIcon::fromTheme(QStringLiteral("applications-internet")), i18n("Open in browser"), this); actionCollection()->addAction(QStringLiteral("open_blog_in_browser"), actOpenBlog); actOpenBlog->setToolTip(i18n("Open current blog in browser")); connect(actOpenBlog, &QAction::triggered, this, &MainWindow::slotOpenCurrentBlogInBrowser); } void MainWindow::loadTempPosts() { QMap tempList = DBMan::self()->listTempPosts(); const int count = tempList.count(); if (count > 0) { QMap::ConstIterator it = tempList.constBegin(); QMap::ConstIterator endIt = tempList.constEnd(); for (; it != endIt; ++it) { createPostEntry(it.value(), (*it.key())); } } else { slotCreateNewPost(); } // activePost = qobject_cast( tabPosts->currentWidget() ); previousActivePostIndex = 0; if (activePost) { setCurrentBlog(activePost->currentPostBlogId()); } } void MainWindow::setCurrentBlog(int blog_id) { qCDebug(BLOGILO_LOG) << blog_id; if (blog_id == -1) { blogs->setCurrentItem(-1); toolbox->setCurrentBlogId(blog_id); // actionCollection()->action("publish_post")->setEnabled( false ); return; } const int count = blogs->items().count(); for (int i = 0; i < count; ++i) { if (blogs->action(i)->data().toInt() == blog_id) { blogs->setCurrentItem(i); currentBlogChanged(blogs->action(i)); break; } } } void MainWindow::currentBlogChanged(QAction *act) { if (act) { if (mCurrentBlogId == act->data().toInt()) { return; } mCurrentBlogId = act->data().toInt(); // __currentBlogId = mCurrentBlogId; if (activePost) { // actionCollection()->action("publish_post")->setEnabled( true ); activePost->setCurrentPostBlogId(mCurrentBlogId); } else { // actionCollection()->action("publish_post")->setEnabled( false ); } blogs->setToolTip(DBMan::self()->blogList().value(mCurrentBlogId)->blogUrl()); } else { mCurrentBlogId = -1; if (activePost) { activePost->setCurrentPostBlogId(mCurrentBlogId); } } toolbox->setCurrentBlogId(mCurrentBlogId); } void MainWindow::slotCreateNewPost() { tabPosts->setCurrentWidget(createPostEntry(mCurrentBlogId, BilboPost())); if (mCurrentBlogId == -1) { if (!blogs->items().isEmpty()) { blogs->setCurrentItem(0); currentBlogChanged(blogs->action(0)); } } if (this->isVisible() == false) { this->show(); } } void MainWindow::optionsPreferences() { // The preference dialog is derived from prefs_base.ui // // compare the names of the widgets in the .ui file // to the names of the variables in the .kcfg file //avoid having 2 dialogs shown if (KConfigDialog::showDialog(QStringLiteral("settings"))) { return; } ConfigureDialog *dialog = new ConfigureDialog(this, QStringLiteral("settings"), Settings::self()); connect(dialog, &ConfigureDialog::blogAdded, this, &MainWindow::slotBlogAdded); connect(dialog, &ConfigureDialog::blogEdited, this, &MainWindow::slotBlogEdited); connect(dialog, &ConfigureDialog::blogRemoved, this, &MainWindow::slotBlogRemoved); connect(dialog, &KConfigDialog::settingsChanged, this, &MainWindow::settingsChanged); connect(dialog, &KConfigDialog::settingsChanged, this, &MainWindow::slotSettingsChanged); connect(dialog, &ConfigureDialog::dialogDestroyed, this, &MainWindow::slotDialogDestroyed); connect(dialog, &ConfigureDialog::configurationChanged, this, &MainWindow::slotSettingsChanged); dialog->show(); } void MainWindow::slotSettingsChanged() { setupSystemTray(); } void MainWindow::slotDialogDestroyed(QObject *win) { const QSize size = qobject_cast(win)->size(); const QString name = win->objectName(); if (name == QLatin1String("settings")) { Settings::setConfigWindowSize(size); } } void MainWindow::addBlog() { AddEditBlog *addEditBlogWindow = new AddEditBlog(-1, this); addEditBlogWindow->setWindowModality(Qt::ApplicationModal); addEditBlogWindow->setAttribute(Qt::WA_DeleteOnClose); connect(addEditBlogWindow, &AddEditBlog::sigBlogAdded, this, &MainWindow::slotBlogAdded); addEditBlogWindow->show(); } void MainWindow::slotBlogAdded(const BilboBlog &blog) { QAction *act = new QAction(blog.title(), blogs); act->setCheckable(true); act->setData(blog.id()); blogs->addAction(act); blogs->setCurrentAction(act); currentBlogChanged(act); toolbox->slotReloadCategoryList(); toolbox->slotUpdateEntries(20); } void MainWindow::slotBlogEdited(const BilboBlog &blog) { const int count = blogs->actions().count(); for (int i = 0; i < count; ++i) { if (blogs->action(i)->data().toInt() == blog.id()) { blogs->action(i)->setText(blog.title()); break; } } } void MainWindow::slotBlogRemoved(int blog_id) { const int count = blogs->actions().count(); for (int i = 0; i < count; ++i) { if (blogs->action(i)->data().toInt() == blog_id) { if (blogs->currentItem() == i) { blogs->setCurrentItem(i - 1); currentBlogChanged(blogs->action(i - 1)); } blogs->removeAction(blogs->action(i)); if (blogs->currentItem() == -1) { toolbox->clearFields(); } break; } } } void MainWindow::setupSystemTray() { if (Settings::enableSysTrayIcon()) { if (!systemTray) { systemTray = new KStatusNotifierItem(this); systemTray->setIconByName(QStringLiteral("blogilo")); systemTray->setToolTip(QStringLiteral("blogilo"), i18n("Blogilo"), i18n("A KDE Blogging Client")); systemTray->contextMenu()->addAction(actionCollection()->action(QStringLiteral("new_post"))); systemTray->setCategory(KStatusNotifierItem::ApplicationStatus); systemTray->setStatus(KStatusNotifierItem::Active); } } else if (systemTray) { systemTray->deleteLater(); systemTray = Q_NULLPTR; } } void MainWindow::slotPostTitleChanged(const QString &title) { tabPosts->setTabText(tabPosts->currentIndex(), title); } void MainWindow::slotToggleToolboxVisible(bool isVisible) { toolboxDock->setVisible(isVisible); } void MainWindow::slotToolboxVisibilityChanged(bool) { actionCollection()->action(QStringLiteral("toggle_toolbox"))->setChecked(toolboxDock->isVisibleTo(this)); } void MainWindow::slotActivePostChanged(int index) { qCDebug(BLOGILO_LOG) << "new post index: " << index << "\tPrev Index: " << previousActivePostIndex; activePost = qobject_cast(tabPosts->widget(index)); PostEntry *prevActivePost = qobject_cast(tabPosts->widget(previousActivePostIndex)); int activePostBlogId = -1; int prevPostBlogId = -1; if ((prevActivePost != Q_NULLPTR) && (index != previousActivePostIndex)) { prevPostBlogId = prevActivePost->currentPostBlogId(); toolbox->getFieldsValue(prevActivePost->currentPost()); prevActivePost->setCurrentPostBlogId(mCurrentBlogId); } if (index >= 0) { activePostBlogId = activePost->currentPostBlogId(); if (activePostBlogId != -1 && activePostBlogId != prevPostBlogId) { setCurrentBlog(activePostBlogId); } toolbox->setFieldsValue(activePost->currentPost()); } else { qCCritical(BLOGILO_LOG) << "ActivePost is NULL! tabPosts Current index is: " << tabPosts->currentIndex(); } previousActivePostIndex = index; } void MainWindow::slotPublishPost() { if (mCurrentBlogId == -1) { KMessageBox::sorry(this, i18n("You have to select a blog to publish this post to.")); return; } if (!activePost || tabPosts->currentIndex() == -1) { KMessageBox::sorry(this, i18n("There is no open post to submit.")); return; } toolbox->getFieldsValue(activePost->currentPost()); activePost->submitPost(mCurrentBlogId, *activePost->currentPost()); } void MainWindow::slotRemoveAllExclude(int pos) { for (int i = tabPosts->count() - 1; i >= 0; --i) { if (i == pos) { continue; } PostEntry *widget = qobject_cast(tabPosts->widget(i)); if (!widget) { if (activePost) { widget = activePost; } else { return; } } DBMan::self()->removeTempEntry(*widget->currentPost()); tabPosts->removeTab(tabPosts->indexOf(widget)); widget->close(); } if (tabPosts->count() < 1) { activePost = Q_NULLPTR; toolbox->resetFields(); // actionCollection()->action("publish_post")->setEnabled( false ); } } void MainWindow::slotRemovePostEntry(int pos) { PostEntry *widget = qobject_cast(tabPosts->widget(pos)); if (!widget) { if (activePost) { widget = activePost; } else { return; } } DBMan::self()->removeTempEntry(*widget->currentPost()); tabPosts->removeTab(tabPosts->indexOf(widget)); widget->close(); if (tabPosts->count() < 1) { activePost = Q_NULLPTR; toolbox->resetFields(); // actionCollection()->action("publish_post")->setEnabled( false ); } } void MainWindow::slotNewPostOpened(BilboPost &newPost, int blog_id) { QWidget *w = createPostEntry(blog_id, newPost); tabPosts->setCurrentWidget(w); } void MainWindow::slotSavePostLocally() { if (activePost && (tabPosts->count() > 0)) { toolbox->getFieldsValue(activePost->currentPost()); activePost->saveLocally(); toolbox->reloadLocalPosts(); } } void MainWindow::slotError(const QString &errorMessage) { qCDebug(BLOGILO_LOG) << "Error message: " << errorMessage; KMessageBox::detailedError(this, i18n("An error occurred in the last transaction."), errorMessage); statusBar()->clearMessage(); slotBusy(false); } void MainWindow::writeConfigs() { if (toolboxDock->isVisible()) { Settings::setShowToolboxOnStart(true); } else { Settings::setShowToolboxOnStart(false); } } void MainWindow::keyPressEvent(QKeyEvent *event) { if (event->modifiers() == Qt::CTRL) { switch (event->key()) { case Qt::Key_1: toolbox->setCurrentPage(0); break; case Qt::Key_2: toolbox->setCurrentPage(1); break; case Qt::Key_3: toolbox->setCurrentPage(2); break; case Qt::Key_4: toolbox->setCurrentPage(3); break; case Qt::Key_5: toolbox->setCurrentPage(4); break; case Qt::Key_W: slotRemovePostEntry(tabPosts->currentIndex()); break; default: KXmlGuiWindow::keyPressEvent(event); break; } } } void MainWindow::postManipulationDone(bool isError, const QString &customMessage) { if (isError) { KMessageBox::detailedError(this, i18n("Submitting post failed"), customMessage); } else { PostEntry *entry = qobject_cast(sender()); if (entry) { if (KMessageBox::questionYesNo(this, i18n("%1\nDo you want to keep the post open?", customMessage), QString(), KStandardGuiItem::yes(), KStandardGuiItem::no(), QStringLiteral("KeepPostOpen")) == KMessageBox::No) { slotRemovePostEntry(tabPosts->indexOf(entry)); } else { toolbox->setFieldsValue(entry->currentPost()); } } toolbox->slotLoadEntriesFromDB(mCurrentBlogId); } this->unsetCursor(); toolbox->unsetCursor(); } void MainWindow::slotBusy(bool isBusy) { qCDebug(BLOGILO_LOG) << "isBusy=" << isBusy << "\tbusyNumber=" << busyNumber; if (isBusy) { this->setCursor(Qt::BusyCursor); toolbox->setCursor(Qt::BusyCursor); ++busyNumber; if (!progress) { progress = new QProgressBar(statusBar()); progress->setMinimum(0); progress->setMaximum(0); progress->setFixedSize(250, 17); statusBar()->addPermanentWidget(progress); } } else { --busyNumber; if (busyNumber < 1) { this->unsetCursor(); toolbox->unsetCursor(); if (progress) { statusBar()->removeWidget(progress); progress->deleteLater(); progress = Q_NULLPTR; } // busyNumber = 0; } } } QWidget *MainWindow::createPostEntry(int blog_id, const BilboPost &post) { PostEntry *temp = new PostEntry(this); temp->setAttribute(Qt::WA_DeleteOnClose); temp->setCurrentPost(post); temp->setCurrentPostBlogId(blog_id); connect(temp, &PostEntry::postTitleChanged, this, &MainWindow::slotPostTitleChanged); connect(temp, &PostEntry::postPublishingDone, this, &MainWindow::postManipulationDone); connect(this, &MainWindow::settingsChanged, temp, &PostEntry::settingsChanged); connect(temp, &PostEntry::showStatusMessage, this, &MainWindow::slotShowStatusMessage); connect(temp, &PostEntry::sigBusy, this, &MainWindow::slotBusy); tabPosts->addTab(temp, post.title()); return temp; } void MainWindow::slotShowStatusMessage(const QString &message, bool isPermanent) { statusBar()->showMessage(message, (isPermanent ? 0 : TIMEOUT)); } void MainWindow::uploadMediaObject() { UploadMediaDialog *uploadDlg = new UploadMediaDialog(this); connect(uploadDlg, &UploadMediaDialog::sigBusy, this, &MainWindow::slotBusy); if (mCurrentBlogId == -1) { uploadDlg->init(Q_NULLPTR); } else { uploadDlg->init(DBMan::self()->blog(mCurrentBlogId)); } } void MainWindow::slotOpenCurrentBlogInBrowser() { if (mCurrentBlogId > -1) { QUrl url(DBMan::self()->blog(mCurrentBlogId)->blogUrl()); if (url.isValid()) { QDesktopServices::openUrl(url); } else { KMessageBox::sorry(this, i18n("Cannot find current blog URL.")); } } ///TODO ///else show a message to the user saying that a blog should be selected before. } diff --git a/grantleeeditor/headerthemeeditor/defaultcompletion.cpp b/grantleeeditor/headerthemeeditor/defaultcompletion.cpp index 0873623355..a0d083afb0 100644 --- a/grantleeeditor/headerthemeeditor/defaultcompletion.cpp +++ b/grantleeeditor/headerthemeeditor/defaultcompletion.cpp @@ -1,100 +1,104 @@ /* Copyright (C) 2013-2016 Montel Laurent 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; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "defaultcompletion.h" QStringList DefaultCompletion::defaultCompetion() { //TODO add to highlighter QStringList lst; lst << QStringLiteral("
") << QStringLiteral("class=\"fancy header\"") << QStringLiteral("header.absoluteThemePath") << QStringLiteral("header.subjecti18n") << QStringLiteral("header.subject") << QStringLiteral("header.replyToi18n") << QStringLiteral("header.replyTo") << QStringLiteral("header.replyToStr") << QStringLiteral("header.toi18n") << QStringLiteral("header.to") << QStringLiteral("header.toStr") << QStringLiteral("header.toExpandable") << QStringLiteral("header.cci18n") << QStringLiteral("header.cc") << QStringLiteral("header.ccStr") << QStringLiteral("header.ccExpandable") << QStringLiteral("header.bcci18n") << QStringLiteral("header.bcc") << QStringLiteral("header.bccStr") << QStringLiteral("header.bccExpandable") << QStringLiteral("header.fromi18n") << QStringLiteral("header.from") << QStringLiteral("header.fromStr") << QStringLiteral("header.spamHTML") << QStringLiteral("header.spamstatusi18n") << QStringLiteral("header.datei18n") << QStringLiteral("header.dateshort") << QStringLiteral("header.date") << QStringLiteral("header.datelong") << QStringLiteral("header.datefancylong") << QStringLiteral("header.datefancyshort") << QStringLiteral("header.datelocalelong") << QStringLiteral("header.useragent") << QStringLiteral("header.xmailer") << QStringLiteral("header.resentfrom") << QStringLiteral("header.resentfromi18n") << QStringLiteral("header.organization") << QStringLiteral("header.vcardname") << QStringLiteral("header.activecolordark") << QStringLiteral("header.fontcolor") << QStringLiteral("header.linkcolor") << QStringLiteral("header.photowidth") << QStringLiteral("header.photoheight") << QStringLiteral("header.applicationDir") << QStringLiteral("header.subjectDir") << QStringLiteral("header.photourl") << QStringLiteral("header.isprinting") << QStringLiteral("header.vcardi18n") << QStringLiteral("header.resentto") << QStringLiteral("header.resenttoi18n") << QStringLiteral("header.trashaction") << QStringLiteral("header.replyaction") << QStringLiteral("header.replyallaction") << QStringLiteral("header.forwardaction") << QStringLiteral("header.newmessageaction") << QStringLiteral("header.printmessageaction") << QStringLiteral("header.printpreviewmessageaction") << QStringLiteral("header.collectionname") << QStringLiteral("header.replyToNameOnly") << QStringLiteral("header.ccNameOnly") << QStringLiteral("header.bccNameOnly") - << QStringLiteral("header.toNameOnly"); + << QStringLiteral("header.toNameOnly") + << QStringLiteral("header.senderi18n") + << QStringLiteral("header.sender") + << QStringLiteral("header.listidi18n") + << QStringLiteral("header.listid"); return lst; } QStringList DefaultCompletion::defaultOptions() { QStringList lst; lst << QStringLiteral("showlink") << QStringLiteral("nameonly") << QStringLiteral("safe") << QStringLiteral("expandable"); return lst; } diff --git a/kaddressbook/src/mainwindow.cpp b/kaddressbook/src/mainwindow.cpp index 70c85ab1f6..1305c212e8 100644 --- a/kaddressbook/src/mainwindow.cpp +++ b/kaddressbook/src/mainwindow.cpp @@ -1,128 +1,128 @@ /* This file is part of KAddressBook. Copyright (c) 2007 Tobias Koenig 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 "mainwindow.h" #include "mainwidget.h" #include "settings.h" #include "xxport/xxportmanager.h" #include #include #include #include #include #include #include #include #include #include #include #include MainWindow::MainWindow() : KXmlGuiWindow(Q_NULLPTR) { mMainWidget = new MainWidget(this, this); setCentralWidget(mMainWidget); initActions(); setStandardToolBarMenuEnabled(true); toolBar()->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); setupGUI(Save | Create, QStringLiteral("kaddressbookui.rc")); setAutoSaveSettings(); slotToggleMenubar(true); } MainWindow::~MainWindow() { } MainWidget *MainWindow::mainWidget() const { return mMainWidget; } void MainWindow::initActions() { KStandardAction::quit(this, &MainWindow::close, actionCollection()); - mHideMenuBarAction = KStandardAction::showMenubar(this, SLOT(slotToggleMenubar()), actionCollection()); + mHideMenuBarAction = KStandardAction::showMenubar(this, &MainWindow::slotToggleMenubar, actionCollection()); QAction *action = KStandardAction::keyBindings(this, &MainWindow::configureKeyBindings, actionCollection()); action->setWhatsThis( i18nc("@info:whatsthis", "You will be presented with a dialog where you can configure " "the application-wide shortcuts.")); KStandardAction::configureToolbars(this, &MainWindow::configureToolbars, actionCollection()); KStandardAction::preferences(this, &MainWindow::configure, actionCollection()); } void MainWindow::configure() { mMainWidget->configure(); } void MainWindow::configureKeyBindings() { if (KShortcutsDialog::configure(actionCollection(), KShortcutsEditor::LetterShortcutsAllowed, this)) { mMainWidget->updateQuickSearchText(); } } void MainWindow::configureToolbars() { KConfigGroup grp = KSharedConfig::openConfig()->group("MainWindow"); saveMainWindowSettings(grp); KEditToolBar dlg(factory()); connect(&dlg, &KEditToolBar::newToolBarConfig, this, &MainWindow::newToolbarConfig); dlg.exec(); } void MainWindow::newToolbarConfig() { createGUI(QStringLiteral("kaddressbookui.rc")); applyMainWindowSettings(KSharedConfig::openConfig()->group("MainWindow")); } void MainWindow::slotToggleMenubar(bool dontShowWarning) { if (menuBar()) { if (mHideMenuBarAction->isChecked()) { menuBar()->show(); } else { if (!dontShowWarning) { const QString accel = mHideMenuBarAction->shortcut().toString(); KMessageBox::information(this, i18n("This will hide the menu bar completely." " You can show it again by typing %1.", accel), i18n("Hide menu bar"), QStringLiteral("HideMenuBarWarning")); } menuBar()->hide(); } Settings::self()->setShowMenuBar(mHideMenuBarAction->isChecked()); } } diff --git a/knotes/src/apps/knotesapp.cpp b/knotes/src/apps/knotesapp.cpp index dcecbc573d..f0e920423b 100644 --- a/knotes/src/apps/knotesapp.cpp +++ b/knotes/src/apps/knotesapp.cpp @@ -1,716 +1,716 @@ /******************************************************************* KNotes -- Notes for the KDE project Copyright (c) 1997-2013, The KNotes Developers 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 "config-knotes.h" #include "configdialog/knoteconfigdialog.h" #include "dialog/knoteselectednotesdialog.h" #include "utils/knoteutils.h" #include "akonadi/notesakonaditreemodel.h" #include "akonadi/noteschangerecorder.h" #include "attributes/notelockattribute.h" #include "attributes/notelockattribute.h" #include "attributes/notealarmattribute.h" #include "attributes/showfoldernotesattribute.h" #include "job/createnewnotejob.h" #include "apps/knotesakonaditray.h" #include "notesharedglobalconfig.h" #include "notes/knote.h" #include "knotesadaptor.h" #include "knotesapp.h" #include "print/knoteprinter.h" #include "print/knoteprintobject.h" #include "knotesglobalconfig.h" #include "dialog/knoteskeydialog.h" #include "dialog/knotedeleteselectednotesdialog.h" #include "print/knoteprintselectednotesdialog.h" #include "finddialog/knotefinddialog.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "knotes_debug.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static bool qActionLessThan(const QAction *a1, const QAction *a2) { return (a1->text() < a2->text()); } KNotesApp::KNotesApp() : QWidget(), m_publisher(Q_NULLPTR), mDebugBaloo(false) { Akonadi::ControlGui::widgetNeedsAkonadi(this); mDebugBaloo = !qEnvironmentVariableIsEmpty("KDEPIM_BALOO_DEBUG"); if (KNotesGlobalConfig::self()->autoCreateResourceOnStart()) { NoteShared::LocalResourceCreator *creator = new NoteShared::LocalResourceCreator(this); creator->createIfMissing(); } new KNotesAdaptor(this); QDBusConnection::sessionBus().registerObject(QStringLiteral("/KNotes"), this); qApp->setQuitOnLastWindowClosed(false); // create the GUI... QAction *action = new QAction(QIcon::fromTheme(QStringLiteral("document-new")), i18n("New Note"), this); actionCollection()->addAction(QStringLiteral("new_note"), action); KGlobalAccel::setGlobalShortcut(action, QKeySequence(Qt::ALT + Qt::SHIFT + Qt::Key_N)); connect(action, SIGNAL(triggered()), SLOT(newNote())); action = new QAction(QIcon::fromTheme(QStringLiteral("edit-paste")), i18n("New Note From Clipboard"), this); actionCollection()->addAction(QStringLiteral("new_note_clipboard"), action); KGlobalAccel::setGlobalShortcut(action, QKeySequence(Qt::ALT + Qt::SHIFT + Qt::Key_C)); connect(action, SIGNAL(triggered()), SLOT(newNoteFromClipboard())); action = new QAction(QIcon::fromTheme(QStringLiteral("document-open")), i18n("New Note From Text File..."), this); actionCollection()->addAction(QStringLiteral("new_note_from_text_file"), action); connect(action, &QAction::triggered, this, &KNotesApp::newNoteFromTextFile); action = new QAction(QIcon::fromTheme(QStringLiteral("knotes")), i18n("Show All Notes"), this); actionCollection()->addAction(QStringLiteral("show_all_notes"), action); KGlobalAccel::setGlobalShortcut(action, QKeySequence(Qt::ALT + Qt::SHIFT + Qt::Key_S)); connect(action, &QAction::triggered, this, &KNotesApp::showAllNotes); action = new QAction(QIcon::fromTheme(QStringLiteral("window-close")), i18n("Hide All Notes"), this); actionCollection()->addAction(QStringLiteral("hide_all_notes"), action); KGlobalAccel::setGlobalShortcut(action, QKeySequence(Qt::ALT + Qt::SHIFT + Qt::Key_H)); connect(action, &QAction::triggered, this, &KNotesApp::hideAllNotes); action = new QAction(QIcon::fromTheme(QStringLiteral("document-print")), i18nc("@action:inmenu", "Print Selected Notes..."), this); actionCollection()->addAction(QStringLiteral("print_selected_notes"), action); connect(action, &QAction::triggered, this, &KNotesApp::slotPrintSelectedNotes); - QAction *act = KStandardAction::find(this, SLOT(slotOpenFindDialog()), actionCollection()); + QAction *act = KStandardAction::find(this, &KNotesApp::slotOpenFindDialog, actionCollection()); action = new QAction(QIcon::fromTheme(QStringLiteral("edit-delete")), i18nc("@action:inmenu", "Delete Selected Notes..."), this); actionCollection()->addAction(QStringLiteral("delete_selected_notes"), action); connect(action, &QAction::triggered, this, &KNotesApp::slotDeleteSelectedNotes); //REmove shortcut here. act->setShortcut(0); #if 0 //QT5 new KHelpMenu(this, KComponentData::mainComponent().aboutData(), false, actionCollection()); #endif KStandardAction::preferences(this, &KNotesApp::slotPreferences, actionCollection()); KStandardAction::keyBindings(this, &KNotesApp::slotConfigureAccels, actionCollection()); //FIXME: no shortcut removing!? KStandardAction::quit(this, &KNotesApp::slotQuit, actionCollection())->setShortcut(0); setXMLFile(QStringLiteral("knotesappui.rc")); m_guiBuilder = new KXMLGUIBuilder(this); m_guiFactory = new KXMLGUIFactory(m_guiBuilder, this); m_guiFactory->addClient(this); QMenu *contextMenu = static_cast(m_guiFactory->container( QStringLiteral("knotes_context"), this)); m_noteMenu = static_cast(m_guiFactory->container( QStringLiteral("notes_menu"), this)); // get the most recent XML UI file QString xmlFileName(componentName() + QLatin1String("ui.rc")); #pragma message("port QT5") QString filter(QLatin1String("kxmlgui5/knotes/") + xmlFileName);//QT5 = componentData().componentName() + QLatin1Char('/') + xmlFileName; const QStringList fileList = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, filter) + QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, xmlFileName);//QT5 = #pragma message("port QT5") //QT5 componentData().dirs()->findAllResources( "data", filter ) + #pragma message("port QT5") //QT5 componentData().dirs()->findAllResources( "data", xmlFileName ); qCDebug(KNOTES_LOG) << " fileList :" << fileList << " filter :" << filter; QString doc; KXMLGUIClient::findMostRecentXMLFile(fileList, doc); m_noteGUI.setContent(doc); // set up the alarm reminder - do it after loading the notes because this // is used as a check if updateNoteActions has to be called for a new note updateNetworkListener(); Akonadi::Session *session = new Akonadi::Session("KNotes Session", this); mNoteRecorder = new NoteShared::NotesChangeRecorder(this); mNoteRecorder->changeRecorder()->setSession(session); mTray = new KNotesAkonadiTray(0); connect(mTray, &KStatusNotifierItem::activateRequested, this, &KNotesApp::slotActivateRequested); connect(mTray, &KStatusNotifierItem::secondaryActivateRequested, this, &KNotesApp::slotSecondaryActivateRequested); mTray->setContextMenu(contextMenu); mNoteTreeModel = new NoteShared::NotesAkonadiTreeModel(mNoteRecorder->changeRecorder(), this); connect(mNoteTreeModel, &QAbstractItemModel::rowsInserted, this, &KNotesApp::slotRowInserted); connect(mNoteRecorder->changeRecorder(), &Akonadi::Monitor::itemChanged, this, &KNotesApp::slotItemChanged); connect(mNoteRecorder->changeRecorder(), &Akonadi::Monitor::itemRemoved, this, &KNotesApp::slotItemRemoved); connect(mNoteRecorder->changeRecorder(), SIGNAL(collectionChanged(Akonadi::Collection,QSet)), SLOT(slotCollectionChanged(Akonadi::Collection,QSet))); connect(qApp, &QGuiApplication::commitDataRequest, this, &KNotesApp::slotCommitData, Qt::DirectConnection); QGuiApplication::setFallbackSessionManagementEnabled(false); updateNoteActions(); } KNotesApp::~KNotesApp() { qDeleteAll(m_noteActions); m_noteActions.clear(); saveNotes(); delete m_guiBuilder; delete mTray; qDeleteAll(mNotes); mNotes.clear(); delete m_publisher; m_publisher = 0; } void KNotesApp::slotDeleteSelectedNotes() { QPointer dlg = new KNoteDeleteSelectedNotesDialog(this); Akonadi::Item::List lst; QHashIterator i(mNotes); while (i.hasNext()) { i.next(); Akonadi::Item item = i.value()->item(); if (!item.hasAttribute()) { lst.append(item); } } dlg->setNotes(lst); if (dlg->exec()) { Akonadi::Item::List lst = dlg->selectedNotes(); if (!lst.isEmpty()) { Akonadi::ItemDeleteJob *deleteJob = new Akonadi::ItemDeleteJob(lst, this); connect(deleteJob, &KJob::result, this, &KNotesApp::slotNoteDeleteFinished); } } delete dlg; } void KNotesApp::slotItemRemoved(const Akonadi::Item &item) { qCDebug(KNOTES_LOG) << " note removed" << item.id(); if (mNotes.contains(item.id())) { delete mNotes.find(item.id()).value(); mNotes.remove(item.id()); updateNoteActions(); updateSystray(); } } void KNotesApp::slotItemChanged(const Akonadi::Item &item, const QSet &set) { if (mNotes.contains(item.id())) { qCDebug(KNOTES_LOG) << " item changed " << item.id() << " info " << set.toList(); KNote *note = mNotes.value(item.id()); note->setChangeItem(item, set); } } void KNotesApp::slotRowInserted(const QModelIndex &parent, int start, int end) { bool needUpdate = false; for (int i = start; i <= end; ++i) { if (mNoteTreeModel->hasIndex(i, 0, parent)) { const QModelIndex child = mNoteTreeModel->index(i, 0, parent); Akonadi::Item item = mNoteTreeModel->data(child, Akonadi::EntityTreeModel::ItemRole).value(); Akonadi::Collection parentCollection = mNoteTreeModel->data(child, Akonadi::EntityTreeModel::ParentCollectionRole).value(); if (parentCollection.hasAttribute()) { createNote(item); needUpdate = true; } } } if (needUpdate) { updateNoteActions(); updateSystray(); } } void KNotesApp::createNote(const Akonadi::Item &item) { if (item.hasPayload()) { //TODO add AllowDebugBaloo KNote *note = new KNote(m_noteGUI, item, mDebugBaloo); mNotes.insert(item.id(), note); connect(note, &KNote::sigShowNextNote, this, &KNotesApp::slotWalkThroughNotes); connect(note, SIGNAL(sigRequestNewNote()), SLOT(newNote())); connect(note, &KNote::sigNameChanged, this, &KNotesApp::updateNoteActions); connect(note, &KNote::sigColorChanged, this, &KNotesApp::updateNoteActions); connect(note, &KNote::sigKillNote, this, &KNotesApp::slotNoteKilled); } } void KNotesApp::updateSystray() { if (KNotesGlobalConfig::self()->systemTrayShowNotes()) { mTray->updateNumberOfNotes(mNotes.count()); } } void KNotesApp::newNote(const QString &name, const QString &text) { NoteShared::CreateNewNoteJob *job = new NoteShared::CreateNewNoteJob(this, this); job->setRichText(KNotesGlobalConfig::self()->richText()); job->setNote(name, text); job->start(); } void KNotesApp::showNote(Akonadi::Item::Id id) const { KNote *note = mNotes.value(id); if (note) { showNote(note); } else { qCWarning(KNOTES_LOG) << "hideNote: no note with id:" << id; } } void KNotesApp::showNote(KNote *note) const { note->show(); #if KDEPIM_HAVE_X11 if (!note->isDesktopAssigned()) { note->toDesktop(KWindowSystem::currentDesktop()); } else { KWindowSystem::setCurrentDesktop( KWindowInfo(note->winId(), NET::WMDesktop).desktop()); } KWindowSystem::forceActiveWindow(note->winId()); #endif note->setFocus(); } void KNotesApp::hideNote(Akonadi::Item::Id id) const { KNote *note = mNotes.value(id); if (note) { note->hide(); } else { qCWarning(KNOTES_LOG) << "hideNote: no note with id:" << id; } } void KNotesApp::hideAllNotes() const { QHashIterator i(mNotes); while (i.hasNext()) { i.next(); i.value()->slotClose(); } } void KNotesApp::showAllNotes() const { QHashIterator i(mNotes); while (i.hasNext()) { i.next(); // workaround to BUG 149116 i.value()->hide(); i.value()->show(); } } void KNotesApp::newNoteFromClipboard(const QString &name) { const QString &text = QApplication::clipboard()->text(); newNote(name, text); } void KNotesApp::newNoteFromTextFile() { QString text; const QString filename = QFileDialog::getOpenFileName(this, i18n("Select Text File"), QString(), i18n("Text File (*.txt)")); if (!filename.isEmpty()) { QFile f(filename); if (f.open(QIODevice::ReadOnly | QIODevice::Text)) { text = QString::fromUtf8(f.readAll()); } else { KMessageBox::error(this, i18n("Error during open text file: %1", f.errorString()), i18n("Open Text File")); return; } newNote(i18n("Note from file '%1'", filename), text); } } void KNotesApp::updateNetworkListener() { delete m_publisher; m_publisher = 0; if (NoteShared::NoteSharedGlobalConfig::receiveNotes()) { // create the socket and start listening for connections m_publisher = new KDNSSD::PublicService(NoteShared::NoteSharedGlobalConfig::senderID(), QStringLiteral("_knotes._tcp"), NoteShared::NoteSharedGlobalConfig::port()); m_publisher->publishAsync(); } } QString KNotesApp::name(Akonadi::Item::Id id) const { KNote *note = mNotes.value(id); if (note) { return note->name(); } return QString(); } QString KNotesApp::text(Akonadi::Item::Id id) const { KNote *note = mNotes.value(id); if (note) { return note->text(); } return QString(); } void KNotesApp::setName(Akonadi::Item::Id id, const QString &newName) { KNote *note = mNotes.value(id); if (note) { note->setName(newName); } else { qCWarning(KNOTES_LOG) << "setName: no note with id:" << id; } } void KNotesApp::setText(Akonadi::Item::Id id, const QString &newText) { KNote *note = mNotes.value(id); if (note) { note->setText(newText); } else { qCWarning(KNOTES_LOG) << "setText: no note with id:" << id; } } void KNotesApp::updateNoteActions() { unplugActionList(QStringLiteral("notes")); m_noteActions.clear(); QHashIterator i(mNotes); while (i.hasNext()) { i.next(); KNote *note = i.value(); QString replaceText; QString realName = note->name(); if (realName.count() > 50) { replaceText = realName.left(50) + QLatin1String("..."); } else { replaceText = realName; } QAction *action = new QAction(replaceText.replace(QLatin1String("&"), QStringLiteral("&&")), this); action->setToolTip(realName); action->setObjectName(QString::number(note->noteId())); connect(action, &QAction::triggered, this, &KNotesApp::slotShowNote); KIconEffect effect; QPixmap icon = effect.apply(qApp->windowIcon().pixmap(IconSize(KIconLoader::Small), IconSize(KIconLoader::Small)), KIconEffect::Colorize, 1, note->palette().color(note->backgroundRole()), false); action->setIcon(icon); m_noteActions.append(action); } if (m_noteActions.isEmpty()) { actionCollection()->action(QStringLiteral("hide_all_notes"))->setEnabled(false); actionCollection()->action(QStringLiteral("show_all_notes"))->setEnabled(false); actionCollection()->action(QStringLiteral("print_selected_notes"))->setEnabled(false); actionCollection()->action(QStringLiteral("edit_find"))->setEnabled(false); QAction *action = new QAction(i18n("No Notes"), this); action->setEnabled(false); m_noteActions.append(action); } else { std::sort(m_noteActions.begin(), m_noteActions.end(), qActionLessThan); actionCollection()->action(QStringLiteral("hide_all_notes"))->setEnabled(true); actionCollection()->action(QStringLiteral("show_all_notes"))->setEnabled(true); actionCollection()->action(QStringLiteral("print_selected_notes"))->setEnabled(true); actionCollection()->action(QStringLiteral("edit_find"))->setEnabled(true); } plugActionList(QStringLiteral("notes"), m_noteActions); } void KNotesApp::slotActivateRequested(bool, const QPoint &) { if (mNotes.size() == 1) { showNote(mNotes.begin().value()); } else { m_noteMenu->popup(QCursor::pos()); } } void KNotesApp::slotSecondaryActivateRequested(const QPoint &) { newNote(); } void KNotesApp::slotShowNote() { // tell the WM to give this note focus showNote(sender()->objectName().toLongLong()); } void KNotesApp::slotWalkThroughNotes() { QHashIterator i(mNotes); while (i.hasNext()) { i.next(); KNote *note = i.value(); if (note->hasFocus()) { if (i.value() != mNotes.end().value()) { showNote(i.value()); } else { showNote(mNotes.begin().value()); } break; } } } void KNotesApp::slotPreferences() { // create a new preferences dialog... KNoteConfigDialog *dialog = new KNoteConfigDialog(i18n("Settings"), this); connect(dialog, SIGNAL(configCommitted()), this, SLOT(slotConfigUpdated())); dialog->show(); } void KNotesApp::slotConfigUpdated() { updateNetworkListener(); KNoteUtils::updateConfiguration(); //Force update if we disable or enable show number in systray mTray->updateNumberOfNotes(mNotes.count()); } void KNotesApp::slotCollectionChanged(const Akonadi::Collection &col, const QSet &set) { if (set.contains("showfoldernotesattribute")) { //qCDebug(KNOTES_LOG)<<" collection Changed "<()) { fetchNotesFromCollection(col); } else { QHashIterator i(mNotes); while (i.hasNext()) { i.next(); Akonadi::Item item = i.value()->item(); if (item.parentCollection() == col) { slotItemRemoved(item); } } } } } void KNotesApp::slotConfigureAccels() { QPointer keys = new KNotesKeyDialog(actionCollection(), this); KActionCollection *actionCollection = 0; if (!mNotes.isEmpty()) { actionCollection = mNotes.begin().value()->actionCollection(); keys->insert(actionCollection); } if (keys->exec()) { keys->save(); // update GUI doc for new notes m_noteGUI.setContent( KXMLGUIFactory::readConfigFile(componentName() + QLatin1String("ui.rc"), componentName()) ); if (actionCollection) { QHashIterator i(mNotes); while (i.hasNext()) { i.next(); foreach (QAction *action, actionCollection->actions()) { QAction *toChange = i.value()->actionCollection()->action(action->objectName()); if (toChange) { toChange->setShortcuts(action->shortcuts()); } } } } } delete keys; } void KNotesApp::slotNoteKilled(Akonadi::Item::Id id) { Akonadi::ItemDeleteJob *deleteJob = new Akonadi::ItemDeleteJob(Akonadi::Item(id), this); connect(deleteJob, &KJob::result, this, &KNotesApp::slotNoteDeleteFinished); } void KNotesApp::slotNoteDeleteFinished(KJob *job) { if (job->error()) { qCWarning(KNOTES_LOG) << job->errorString(); return; } } void KNotesApp::slotPrintSelectedNotes() { QPointer dlg = new KNotePrintSelectedNotesDialog(this); dlg->setNotes(mNotes); if (dlg->exec()) { const QList lst = dlg->selectedNotes(); if (!lst.isEmpty()) { const QString selectedTheme = dlg->selectedTheme(); KNotePrinter printer; printer.printNotes(lst, selectedTheme, dlg->preview()); qDeleteAll(lst); } } delete dlg; } void KNotesApp::saveNotes(bool force, bool sync) { KNotesGlobalConfig::self()->save(); QHashIterator i(mNotes); while (i.hasNext()) { i.next(); i.value()->saveNote(force, sync); } } void KNotesApp::slotQuit() { saveNotes(true, true); qApp->quit(); } void KNotesApp::slotCommitData(QSessionManager &) { saveNotes(true, true); } void KNotesApp::slotSelectNote(Akonadi::Item::Id id) { showNote(id); } void KNotesApp::slotOpenFindDialog() { if (!mFindDialog) { mFindDialog = new KNoteFindDialog(this); connect(mFindDialog.data(), &KNoteFindDialog::noteSelected, this, &KNotesApp::slotSelectNote); } QHash lst; QHashIterator i(mNotes); while (i.hasNext()) { i.next(); lst.insert(i.key(), i.value()->item()); } mFindDialog->setExistingNotes(lst); mFindDialog->show(); } void KNotesApp::fetchNotesFromCollection(const Akonadi::Collection &col) { Akonadi::ItemFetchJob *job = new Akonadi::ItemFetchJob(col); job->fetchScope().fetchFullPayload(true); job->fetchScope().fetchAttribute(); job->fetchScope().fetchAttribute(); job->fetchScope().fetchAttribute(); job->fetchScope().setAncestorRetrieval(Akonadi::ItemFetchScope::Parent); connect(job, &KJob::result, this, &KNotesApp::slotItemFetchFinished); } void KNotesApp::slotItemFetchFinished(KJob *job) { if (job->error()) { qCDebug(KNOTES_LOG) << "Error occurred during item fetch:" << job->errorString(); return; } Akonadi::ItemFetchJob *fetchJob = qobject_cast(job); const Akonadi::Item::List items = fetchJob->items(); foreach (const Akonadi::Item &item, items) { createNote(item); } if (!items.isEmpty()) { updateNoteActions(); updateSystray(); } } diff --git a/korganizer/korgac/alarmdockwindow.cpp b/korganizer/korgac/alarmdockwindow.cpp index ace75a52a5..00f33c1e9c 100644 --- a/korganizer/korgac/alarmdockwindow.cpp +++ b/korganizer/korgac/alarmdockwindow.cpp @@ -1,212 +1,212 @@ /* This file is part of KOrganizer. This file is part of the KDE reminder agent. Copyright (c) 2003 Cornelius Schumacher Copyright (c) 2008-2009 Allen Winter 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. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #include "alarmdockwindow.h" #include #include #include #include #include #include #include #include #include #include #include #include "koalarmclient_debug.h" AlarmDockWindow::AlarmDockWindow() : KStatusNotifierItem(0) { // Read the autostart status from the config file KConfigGroup config(KSharedConfig::openConfig(), "General"); const bool autostartSet = config.hasKey("Autostart"); const bool autostart = config.readEntry("Autostart", true); const bool alarmsEnabled = config.readEntry("Enabled", true); mName = i18nc("@title:window", "KOrganizer Reminder Daemon"); setToolTipTitle(mName); setToolTipIconByName(QStringLiteral("korgac")); // Set up icons KIconLoader::global()->addAppDir(QStringLiteral("korgac")); QString iconPath = KIconLoader::global()->iconPath(QStringLiteral("korgac"), KIconLoader::Panel); QIcon iconEnabled = QIcon(iconPath); if (iconEnabled.isNull()) { KMessageBox::sorry(associatedWidget(), i18nc("@info", "Cannot load system tray icon.")); } else { KIconLoader loader; QImage iconDisabled = iconEnabled.pixmap(loader.currentSize(KIconLoader::Panel)).toImage(); KIconEffect::toGray(iconDisabled, 1.0); mIconDisabled = QIcon(QPixmap::fromImage(iconDisabled)); } changeSystrayIcon(alarmsEnabled); // Set up the context menu mSuspendAll = contextMenu()->addAction(i18nc("@action:inmenu", "Suspend All Reminders"), this, - SLOT(slotSuspendAll())); + &AlarmDockWindow::slotSuspendAll); mDismissAll = contextMenu()->addAction(i18nc("@action:inmenu", "Dismiss All Reminders"), this, - SLOT(slotDismissAll())); + &AlarmDockWindow::slotDismissAll); mSuspendAll->setEnabled(false); mDismissAll->setEnabled(false); contextMenu()->addSeparator(); mAlarmsEnabled = contextMenu()->addAction(i18nc("@action:inmenu", "Enable Reminders")); connect(mAlarmsEnabled, &QAction::toggled, this, &AlarmDockWindow::toggleAlarmsEnabled); mAlarmsEnabled->setCheckable(true); mAutostart = contextMenu()->addAction(i18nc("@action:inmenu", "Start Reminder Daemon at Login")); connect(mAutostart, &QAction::toggled, this, &AlarmDockWindow::toggleAutostart); mAutostart->setCheckable(true); mAlarmsEnabled->setChecked(alarmsEnabled); mAutostart->setChecked(autostart); // Disable standard quit behaviour. We have to intercept the quit even, // if the main window is hidden. QAction *act = action(QStringLiteral("quit")); if (act) { act->disconnect(SIGNAL(triggered(bool)), this, SLOT(maybeQuit())); connect(act, &QAction::triggered, this, &AlarmDockWindow::slotQuit); } else { qCDebug(KOALARMCLIENT_LOG) << "No Quit standard action."; } mAutostartSet = autostartSet; } AlarmDockWindow::~AlarmDockWindow() { } void AlarmDockWindow::slotUpdate(int reminders) { const bool actif = (reminders > 0); mSuspendAll->setEnabled(actif); mDismissAll->setEnabled(actif); if (actif) { setToolTip(QStringLiteral("korgac"), mName, i18ncp("@info:status", "There is 1 active reminder.", "There are %1 active reminders.", reminders)); } else { setToolTip(QStringLiteral("korgac"), mName, i18nc("@info:status", "No active reminders.")); } } void AlarmDockWindow::toggleAlarmsEnabled(bool checked) { changeSystrayIcon(checked); KConfigGroup config(KSharedConfig::openConfig(), "General"); config.writeEntry("Enabled", checked); config.sync(); } void AlarmDockWindow::toggleAutostart(bool checked) { qCDebug(KOALARMCLIENT_LOG); mAutostartSet = true; enableAutostart(checked); } void AlarmDockWindow::slotSuspendAll() { Q_EMIT suspendAllSignal(); } void AlarmDockWindow::slotDismissAll() { Q_EMIT dismissAllSignal(); } void AlarmDockWindow::enableAutostart(bool enable) { KConfigGroup config(KSharedConfig::openConfig(), "General"); config.writeEntry("Autostart", enable); config.sync(); } void AlarmDockWindow::activate(const QPoint &pos) { Q_UNUSED(pos); KToolInvocation::startServiceByDesktopName(QStringLiteral("korganizer"), QString()); } void AlarmDockWindow::slotQuit() { if (mAutostartSet == true) { int result = KMessageBox::warningContinueCancel( associatedWidget(), xi18nc("@info", "Do you want to quit the KOrganizer reminder daemon?" " you will not get calendar reminders unless the daemon is running."), i18nc("@title:window", "Close KOrganizer Reminder Daemon"), KStandardGuiItem::quit()); if (result == KMessageBox::Continue) { Q_EMIT quitSignal(); } } else { int result = KMessageBox::questionYesNoCancel( associatedWidget(), xi18nc("@info", "Do you want to start the KOrganizer reminder daemon at login?" " you will not get calendar reminders unless the daemon is running."), i18nc("@title:window", "Close KOrganizer Reminder Daemon"), KGuiItem(i18nc("@action:button start the reminder daemon", "Start")), KGuiItem(i18nc("@action:button do not start the reminder daemon", "Do Not Start")), KStandardGuiItem::cancel(), QStringLiteral("AskForStartAtLogin")); bool autostart = true; if (result == KMessageBox::No) { autostart = false; } enableAutostart(autostart); if (result != KMessageBox::Cancel) { Q_EMIT quitSignal(); } } } void AlarmDockWindow::changeSystrayIcon(bool alarmsEnabled) { if (alarmsEnabled) { setIconByName(QStringLiteral("korgac")); } else { setIconByPixmap(mIconDisabled.pixmap(22, 22)); } } diff --git a/sieveeditor/src/sieveeditormainwidget.h b/sieveeditor/src/sieveeditormainwidget.h index 79ec7c4867..5a6ff241a0 100644 --- a/sieveeditor/src/sieveeditormainwidget.h +++ b/sieveeditor/src/sieveeditormainwidget.h @@ -1,121 +1,121 @@ /* Copyright (C) 2013-2016 Montel Laurent 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; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef SIEVEEDITORMAINWIDGET_H #define SIEVEEDITORMAINWIDGET_H #include #include #include "ksieveui/sieveeditorwidget.h" class QTabWidget; class QStackedWidget; class SieveEditorTabWidget; class SieveEditorScriptManagerWidget; class SieveEditorPageWidget; class SieveEditorEmptyTabWidgetLabel; class SieveEditorMainWidget : public QSplitter { Q_OBJECT public: explicit SieveEditorMainWidget(QWidget *parent = Q_NULLPTR); ~SieveEditorMainWidget(); void createNewScript(); void deleteScript(); void updateServerList(); void editScript(); void desactivateScript(); void refreshList(); void uploadScript(); bool needToSaveScript(); QTabWidget *tabWidget() const; KSieveUi::SieveEditorWidget::EditorMode pageMode() const; bool isUndoAvailable() const; bool isRedoAvailable() const; bool isWordWrap() const; bool hasSelection() const; QString currentHelpTitle() const; QUrl currentHelpUrl() const; void openBookmarkUrl(const QUrl &url); bool printSupportEnabled() const; bool isTextEditor() const; public Q_SLOTS: void slotDebugSieveScript(); void slotGoToLine(); void slotReplace(); void slotFind(); void slotCopy(); void slotPaste(); void slotCut(); void slotSaveAs(); void slotCheckSpelling(); void slotShareScript(); void slotImport(); void slotAutoGenerateScript(); void slotCheckSyntax(); void slotComment(); void slotUncomment(); void slotUpperCase(); void slotSentenceCase(); void slotLowerCase(); void slotReverseCase(); void slotZoomIn(); void slotZoomOut(); void slotZoomReset(); void slotWordWrap(bool); void slotPrintPreview(); void slotPrint(); + void slotUndo(); + void slotRedo(); + void slotSelectAll(); Q_SIGNALS: void updateButtons(bool newScriptAction, bool editScriptAction, bool deleteScriptAction, bool desactivateScriptAction); void updateScriptList(); void modeEditorChanged(KSieveUi::SieveEditorWidget::EditorMode); void serverSieveFound(bool); void undoAvailable(bool); void redoAvailable(bool); void copyAvailable(bool); void sieveEditorTabCurrentChanged(); private Q_SLOTS: void slotCreateScriptPage(const QUrl &url, const QStringList &capabilities, bool isNewScript); void slotScriptDeleted(const QUrl &url); void slotScriptModified(bool modified, SieveEditorPageWidget *page); void slotGeneralPaletteChanged(); void slotTabCloseRequested(int index); void slotTabRemoveAllExclude(int index); - void slotUndo(); - void slotRedo(); - void slotSelectAll(); void slotTabCloseAllRequested(); private: void updateStackedWidget(); QWidget *hasExistingPage(const QUrl &url); QColor mModifiedScriptColor; QColor mScriptColor; SieveEditorTabWidget *mTabWidget; SieveEditorScriptManagerWidget *mScriptManagerWidget; QStackedWidget *mStackedWidget; SieveEditorEmptyTabWidgetLabel *mEditorEmptyLabel; }; #endif // SIEVEEDITORMAINWIDGET_H diff --git a/sieveeditor/src/sieveeditormainwindow.cpp b/sieveeditor/src/sieveeditormainwindow.cpp index eb5fdb35a6..10d9e3e37c 100644 --- a/sieveeditor/src/sieveeditormainwindow.cpp +++ b/sieveeditor/src/sieveeditormainwindow.cpp @@ -1,382 +1,382 @@ /* Copyright (C) 2013-2016 Montel Laurent 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; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "sieveeditormainwindow.h" #include "sieveeditormainwidget.h" #include "sieveeditorconfiguredialog.h" #include "serversievesettingsdialog.h" #include "sieveserversettings.h" #include "sieveeditorcentralwidget.h" #include "sieveeditorglobalconfig.h" #include "sieveeditorbookmarks.h" #include "PimCommon/KActionMenuChangeCase" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include SieveEditorMainWindow::SieveEditorMainWindow() : KXmlGuiWindow() { mMainWidget = new SieveEditorCentralWidget(this); connect(mMainWidget, &SieveEditorCentralWidget::configureClicked, this, &SieveEditorMainWindow::slotConfigure); connect(mMainWidget->sieveEditorMainWidget(), &SieveEditorMainWidget::updateButtons, this, &SieveEditorMainWindow::slotUpdateButtons); setCentralWidget(mMainWidget); setupActions(); setupGUI(); readConfig(); initStatusBar(); mNetworkConfigurationManager = new QNetworkConfigurationManager(); connect(mNetworkConfigurationManager, &QNetworkConfigurationManager::onlineStateChanged, this, &SieveEditorMainWindow::slotSystemNetworkOnlineStateChanged); connect(mMainWidget->sieveEditorMainWidget()->tabWidget(), &QTabWidget::currentChanged, this, &SieveEditorMainWindow::slotUpdateActions); connect(mMainWidget->sieveEditorMainWidget(), &SieveEditorMainWidget::modeEditorChanged, this, &SieveEditorMainWindow::slotUpdateActions); slotSystemNetworkOnlineStateChanged(mNetworkConfigurationManager->isOnline()); connect(mMainWidget->sieveEditorMainWidget(), &SieveEditorMainWidget::undoAvailable, this, &SieveEditorMainWindow::slotUndoAvailable); connect(mMainWidget->sieveEditorMainWidget(), &SieveEditorMainWidget::redoAvailable, this, &SieveEditorMainWindow::slotRedoAvailable); connect(mMainWidget->sieveEditorMainWidget(), &SieveEditorMainWidget::copyAvailable, this, &SieveEditorMainWindow::slotCopyAvailable); connect(mMainWidget->sieveEditorMainWidget(), &SieveEditorMainWidget::sieveEditorTabCurrentChanged, this, &SieveEditorMainWindow::slotUpdateActions); mMainWidget->sieveEditorMainWidget()->refreshList(); } SieveEditorMainWindow::~SieveEditorMainWindow() { KSharedConfig::Ptr config = KSharedConfig::openConfig(); KConfigGroup group = config->group(QStringLiteral("SieveEditorMainWindow")); group.writeEntry("Size", size()); if (SieveEditorGlobalConfig::self()->closeWallet()) { SieveServerSettings::self()->closeWallet(); } } void SieveEditorMainWindow::initStatusBar() { mStatusBarInfo = new QLabel; statusBar()->insertWidget(0, mStatusBarInfo, 4); } void SieveEditorMainWindow::slotSystemNetworkOnlineStateChanged(bool state) { if (state) { mStatusBarInfo->setText(i18n("Network is Up.")); } else { mStatusBarInfo->setText(i18n("Network is Down.")); } mMainWidget->sieveEditorMainWidget()->setEnabled(state); slotUpdateActions(); } void SieveEditorMainWindow::slotUpdateButtons(bool newScriptAction, bool editScriptAction, bool deleteScriptAction, bool desactivateScriptAction) { mDeleteScript->setEnabled(deleteScriptAction); mNewScript->setEnabled(newScriptAction); mEditScript->setEnabled(editScriptAction); mDesactivateScript->setEnabled(desactivateScriptAction); } void SieveEditorMainWindow::readConfig() { KSharedConfig::Ptr config = KSharedConfig::openConfig(); KConfigGroup group = KConfigGroup(config, "SieveEditorMainWindow"); const QSize sizeDialog = group.readEntry("Size", QSize(800, 600)); if (sizeDialog.isValid()) { resize(sizeDialog); } } void SieveEditorMainWindow::setupActions() { KActionCollection *ac = actionCollection(); KStandardAction::quit(this, &SieveEditorMainWindow::close, ac); KStandardAction::preferences(this, &SieveEditorMainWindow::slotConfigure, ac); mUploadScript = KStandardAction::save(this, &SieveEditorMainWindow::slotUploadScript, ac); mUploadScript->setText(i18n("Upload")); mUploadScript->setEnabled(false); QAction *act = ac->addAction(QStringLiteral("add_server_sieve"), this, SLOT(slotAddServerSieve())); act->setText(i18n("Add Sieve Server...")); mDeleteScript = ac->addAction(QStringLiteral("delete_script"), this, SLOT(slotDeleteScript())); mDeleteScript->setText(i18n("Delete Script")); ac->setDefaultShortcut(mDeleteScript, QKeySequence(Qt::Key_Delete)); mDeleteScript->setEnabled(false); mNewScript = ac->addAction(QStringLiteral("create_new_script"), this, SLOT(slotCreateNewScript())); ac->setDefaultShortcut(mNewScript, QKeySequence(Qt::CTRL + Qt::Key_N)); mNewScript->setText(i18n("Create New Script...")); mNewScript->setEnabled(false); mEditScript = ac->addAction(QStringLiteral("edit_script"), this, SLOT(slotEditScript())); mEditScript->setText(i18n("Edit Script...")); mEditScript->setEnabled(false); mDesactivateScript = ac->addAction(QStringLiteral("desactivate_script"), this, SLOT(slotDesactivateScript())); mDesactivateScript->setText(i18n("Deactivate Script")); mDesactivateScript->setEnabled(false); mRefreshList = ac->addAction(QStringLiteral("refresh_list"), this, SLOT(slotRefreshList())); mRefreshList->setText(i18n("Refresh List")); mRefreshList->setIcon(QIcon::fromTheme(QStringLiteral("view-refresh"))); ac->setDefaultShortcut(mRefreshList, QKeySequence(Qt::Key_F5)); mGoToLine = ac->addAction(QStringLiteral("gotoline"), mMainWidget->sieveEditorMainWidget(), SLOT(slotGoToLine())); mGoToLine->setText(i18n("Go to Line...")); mGoToLine->setIcon(QIcon::fromTheme(QStringLiteral("go-jump"))); ac->setDefaultShortcut(mGoToLine, QKeySequence(Qt::CTRL + Qt::Key_G)); mGoToLine->setEnabled(false); - mFindAction = KStandardAction::find(mMainWidget->sieveEditorMainWidget(), SLOT(slotFind()), ac); - mReplaceAction = KStandardAction::replace(mMainWidget->sieveEditorMainWidget(), SLOT(slotReplace()), ac); - mUndoAction = KStandardAction::undo(mMainWidget->sieveEditorMainWidget(), SLOT(slotUndo()), ac); - mRedoAction = KStandardAction::redo(mMainWidget->sieveEditorMainWidget(), SLOT(slotRedo()), ac); - mCopyAction = KStandardAction::copy(mMainWidget->sieveEditorMainWidget(), SLOT(slotCopy()), ac); - mPasteAction = KStandardAction::paste(mMainWidget->sieveEditorMainWidget(), SLOT(slotPaste()), ac); - mCutAction = KStandardAction::cut(mMainWidget->sieveEditorMainWidget(), SLOT(slotCut()), ac); - mSelectAllAction = KStandardAction::selectAll(mMainWidget->sieveEditorMainWidget(), SLOT(slotSelectAll()), ac); - mSaveAsAction = KStandardAction::saveAs(mMainWidget->sieveEditorMainWidget(), SLOT(slotSaveAs()), ac); + mFindAction = KStandardAction::find(mMainWidget->sieveEditorMainWidget(), &SieveEditorMainWidget::slotFind, ac); + mReplaceAction = KStandardAction::replace(mMainWidget->sieveEditorMainWidget(), &SieveEditorMainWidget::slotReplace, ac); + mUndoAction = KStandardAction::undo(mMainWidget->sieveEditorMainWidget(), &SieveEditorMainWidget::slotUndo, ac); + mRedoAction = KStandardAction::redo(mMainWidget->sieveEditorMainWidget(), &SieveEditorMainWidget::slotRedo, ac); + mCopyAction = KStandardAction::copy(mMainWidget->sieveEditorMainWidget(), &SieveEditorMainWidget::slotCopy, ac); + mPasteAction = KStandardAction::paste(mMainWidget->sieveEditorMainWidget(), &SieveEditorMainWidget::slotPaste, ac); + mCutAction = KStandardAction::cut(mMainWidget->sieveEditorMainWidget(), &SieveEditorMainWidget::slotCut, ac); + mSelectAllAction = KStandardAction::selectAll(mMainWidget->sieveEditorMainWidget(), &SieveEditorMainWidget::slotSelectAll, ac); + mSaveAsAction = KStandardAction::saveAs(mMainWidget->sieveEditorMainWidget(), &SieveEditorMainWidget::slotSaveAs, ac); mImportAction = ac->addAction(QStringLiteral("import_script"), mMainWidget->sieveEditorMainWidget(), SLOT(slotImport())); mImportAction->setText(i18n("Import...")); mImportAction->setEnabled(false); mShareAction = ac->addAction(QStringLiteral("share_script"), mMainWidget->sieveEditorMainWidget(), SLOT(slotShareScript())); mShareAction->setText(i18n("Share...")); const QStringList overlays = QStringList() << QStringLiteral("list-add"); mShareAction->setIcon(QIcon(new KIconEngine(QStringLiteral("get-hot-new-stuff"), KIconLoader::global(), overlays))); mShareAction->setEnabled(false); mSpellCheckAction = ac->addAction(QStringLiteral("check_spelling"), mMainWidget->sieveEditorMainWidget(), SLOT(slotCheckSpelling())); mSpellCheckAction->setIcon(QIcon::fromTheme(QStringLiteral("tools-check-spelling"))); mSpellCheckAction->setText(i18n("Check Spelling...")); mSpellCheckAction->setEnabled(false); mCheckSyntaxAction = ac->addAction(QStringLiteral("check_syntax"), mMainWidget->sieveEditorMainWidget(), SLOT(slotCheckSyntax())); mCheckSyntaxAction->setText(i18n("Check Syntax")); mCheckSyntaxAction->setEnabled(false); mAutoGenerateScriptAction = ac->addAction(QStringLiteral("autogenerate_script"), mMainWidget->sieveEditorMainWidget(), SLOT(slotAutoGenerateScript())); mAutoGenerateScriptAction->setText(i18n("Autogenerate Script...")); mAutoGenerateScriptAction->setEnabled(false); mCommentAction = ac->addAction(QStringLiteral("comment_code"), mMainWidget->sieveEditorMainWidget(), SLOT(slotComment())); ac->setDefaultShortcut(mCommentAction, Qt::CTRL + Qt::Key_D); mCommentAction->setText(i18n("Comment")); mUncommentAction = ac->addAction(QStringLiteral("uncomment_code"), mMainWidget->sieveEditorMainWidget(), SLOT(slotUncomment())); ac->setDefaultShortcut(mUncommentAction, Qt::CTRL + Qt::SHIFT + Qt::Key_D); mUncommentAction->setText(i18n("Uncomment")); mZoomInAction = new QAction(QIcon::fromTheme(QStringLiteral("zoom-in")), i18n("&Zoom In"), this); ac->addAction(QStringLiteral("zoom_in"), mZoomInAction); connect(mZoomInAction, &QAction::triggered, mMainWidget->sieveEditorMainWidget(), &SieveEditorMainWidget::slotZoomIn); ac->setDefaultShortcut(mZoomInAction, QKeySequence(Qt::CTRL + Qt::Key_Plus)); mZoomOutAction = new QAction(QIcon::fromTheme(QStringLiteral("zoom-out")), i18n("Zoom &Out"), this); ac->addAction(QStringLiteral("zoom_out"), mZoomOutAction); connect(mZoomOutAction, &QAction::triggered, mMainWidget->sieveEditorMainWidget(), &SieveEditorMainWidget::slotZoomOut); ac->setDefaultShortcut(mZoomOutAction, QKeySequence(Qt::CTRL + Qt::Key_Minus)); mZoomResetAction = ac->addAction(QStringLiteral("zoom_reset"), mMainWidget->sieveEditorMainWidget(), SLOT(slotZoomReset())); ac->setDefaultShortcut(mZoomResetAction, QKeySequence(Qt::CTRL + Qt::Key_0)); mZoomResetAction->setText(i18nc("Reset the zoom", "Reset")); mMenuChangeCaseAction = new PimCommon::KActionMenuChangeCase(this); ac->addAction(QStringLiteral("change_case_menu"), mMenuChangeCaseAction); mMenuChangeCaseAction->appendInActionCollection(ac); connect(mMenuChangeCaseAction, &PimCommon::KActionMenuChangeCase::upperCase, mMainWidget->sieveEditorMainWidget(), &SieveEditorMainWidget::slotUpperCase); connect(mMenuChangeCaseAction, &PimCommon::KActionMenuChangeCase::lowerCase, mMainWidget->sieveEditorMainWidget(), &SieveEditorMainWidget::slotLowerCase); connect(mMenuChangeCaseAction, &PimCommon::KActionMenuChangeCase::sentenceCase, mMainWidget->sieveEditorMainWidget(), &SieveEditorMainWidget::slotSentenceCase); connect(mMenuChangeCaseAction, &PimCommon::KActionMenuChangeCase::reverseCase, mMainWidget->sieveEditorMainWidget(), &SieveEditorMainWidget::slotReverseCase); mBookmarkMenu = new KActionMenu(i18nc("@title:menu", "&Bookmarks"), ac); mSieveEditorBookmarks = new SieveEditorBookmarks(this, ac, mBookmarkMenu->menu(), this); ac->addAction(QStringLiteral("bookmark"), mBookmarkMenu); connect(mSieveEditorBookmarks, &SieveEditorBookmarks::openUrl, this, &SieveEditorMainWindow::slotOpenBookmarkUrl); mDebugSieveScriptAction = ac->addAction(QStringLiteral("debug_sieve"), mMainWidget->sieveEditorMainWidget(), SLOT(slotDebugSieveScript())); mDebugSieveScriptAction->setText(i18n("Debug Sieve Script...")); ac->setDefaultShortcut(mDebugSieveScriptAction, QKeySequence(Qt::SHIFT + Qt::ALT + Qt::Key_D)); mWrapTextAction = new QAction(i18n("Wordwarp"), this); mWrapTextAction->setCheckable(true); ac->addAction(QStringLiteral("wordwrap"), mWrapTextAction); connect(mWrapTextAction, &QAction::triggered, mMainWidget->sieveEditorMainWidget(), &SieveEditorMainWidget::slotWordWrap); mPrintAction = KStandardAction::print(mMainWidget->sieveEditorMainWidget(), SLOT(slotPrint()), ac); - mPrintPreviewAction = KStandardAction::printPreview(mMainWidget->sieveEditorMainWidget(), SLOT(slotPrintPreview()), ac); + mPrintPreviewAction = KStandardAction::printPreview(mMainWidget->sieveEditorMainWidget(), &SieveEditorMainWidget::slotPrintPreview, ac); } void SieveEditorMainWindow::slotRefreshList() { if (mNetworkConfigurationManager->isOnline()) { mMainWidget->sieveEditorMainWidget()->refreshList(); } } void SieveEditorMainWindow::slotUploadScript() { mMainWidget->sieveEditorMainWidget()->uploadScript(); } void SieveEditorMainWindow::slotDesactivateScript() { mMainWidget->sieveEditorMainWidget()->desactivateScript(); } void SieveEditorMainWindow::slotEditScript() { mMainWidget->sieveEditorMainWidget()->editScript(); } void SieveEditorMainWindow::slotCreateNewScript() { mMainWidget->sieveEditorMainWidget()->createNewScript(); } void SieveEditorMainWindow::slotDeleteScript() { mMainWidget->sieveEditorMainWidget()->deleteScript(); } void SieveEditorMainWindow::closeEvent(QCloseEvent *e) { if (mMainWidget->sieveEditorMainWidget()->needToSaveScript()) { e->ignore(); return; } else { e->accept(); } } void SieveEditorMainWindow::slotConfigure() { QPointer dlg = new SieveEditorConfigureDialog(this); if (dlg->exec()) { dlg->saveServerSieveConfig(); mMainWidget->sieveEditorMainWidget()->updateServerList(); } delete dlg; } void SieveEditorMainWindow::slotAddServerSieve() { QPointer dlg = new ServerSieveSettingsDialog(this); if (dlg->exec()) { const SieveEditorUtil::SieveServerConfig conf = dlg->serverSieveConfig(); SieveEditorUtil::addServerSieveConfig(conf); mMainWidget->sieveEditorMainWidget()->updateServerList(); } delete dlg; } void SieveEditorMainWindow::slotUpdateActions() { const bool hasPage = (mMainWidget->sieveEditorMainWidget()->tabWidget()->count() > 0); mUploadScript->setEnabled(hasPage); const bool editActionEnabled = (hasPage && mMainWidget->sieveEditorMainWidget()->isTextEditor()); const bool hasActionInHtmlModeToo = (hasPage && mMainWidget->sieveEditorMainWidget()->pageMode() == KSieveUi::SieveEditorWidget::TextMode); mGoToLine->setEnabled(editActionEnabled); mFindAction->setEnabled(editActionEnabled); mReplaceAction->setEnabled(editActionEnabled); mUndoAction->setEnabled(editActionEnabled && mMainWidget->sieveEditorMainWidget()->isUndoAvailable()); mRedoAction->setEnabled(editActionEnabled && mMainWidget->sieveEditorMainWidget()->isRedoAvailable()); mCopyAction->setEnabled(hasActionInHtmlModeToo && mMainWidget->sieveEditorMainWidget()->hasSelection()); mPasteAction->setEnabled(editActionEnabled); mCutAction->setEnabled(editActionEnabled && mMainWidget->sieveEditorMainWidget()->hasSelection()); mSelectAllAction->setEnabled(hasActionInHtmlModeToo); mUploadScript->setEnabled(hasPage && !mNetworkIsDown); mRefreshList->setEnabled(!mNetworkIsDown); mSaveAsAction->setEnabled(hasPage); mImportAction->setEnabled(hasPage); mShareAction->setEnabled(hasPage && !mNetworkIsDown); mSpellCheckAction->setEnabled(editActionEnabled); mCheckSyntaxAction->setEnabled(editActionEnabled && !mNetworkIsDown); mAutoGenerateScriptAction->setEnabled(editActionEnabled); mCommentAction->setEnabled(editActionEnabled); mUncommentAction->setEnabled(editActionEnabled); mMenuChangeCaseAction->setEnabled(editActionEnabled); mZoomInAction->setEnabled(hasActionInHtmlModeToo); mZoomOutAction->setEnabled(hasActionInHtmlModeToo); mZoomResetAction->setEnabled(hasActionInHtmlModeToo); mBookmarkMenu->setEnabled(hasActionInHtmlModeToo); mDebugSieveScriptAction->setEnabled(editActionEnabled); mWrapTextAction->setEnabled(editActionEnabled); mWrapTextAction->setChecked(mMainWidget->sieveEditorMainWidget()->isWordWrap()); mPrintAction->setEnabled(editActionEnabled && mMainWidget->sieveEditorMainWidget()->printSupportEnabled()); mPrintPreviewAction->setEnabled(editActionEnabled && mMainWidget->sieveEditorMainWidget()->printSupportEnabled()); } void SieveEditorMainWindow::slotUndoAvailable(bool b) { const bool hasPage = (mMainWidget->sieveEditorMainWidget()->tabWidget()->count() > 0); const bool editActionEnabled = (hasPage && mMainWidget->sieveEditorMainWidget()->pageMode() == KSieveUi::SieveEditorWidget::TextMode); mUndoAction->setEnabled(editActionEnabled && b); } void SieveEditorMainWindow::slotRedoAvailable(bool b) { const bool hasPage = (mMainWidget->sieveEditorMainWidget()->tabWidget()->count() > 0); const bool editActionEnabled = (hasPage && mMainWidget->sieveEditorMainWidget()->pageMode() == KSieveUi::SieveEditorWidget::TextMode); mRedoAction->setEnabled(editActionEnabled && b); } void SieveEditorMainWindow::slotCopyAvailable(bool b) { const bool hasPage = (mMainWidget->sieveEditorMainWidget()->tabWidget()->count() > 0); const bool editActionEnabled = (hasPage && mMainWidget->sieveEditorMainWidget()->pageMode() == KSieveUi::SieveEditorWidget::TextMode); mCopyAction->setEnabled(editActionEnabled && b); mCutAction->setEnabled(editActionEnabled && b); } void SieveEditorMainWindow::slotOpenBookmarkUrl(const QUrl &url) { mMainWidget->sieveEditorMainWidget()->openBookmarkUrl(url); } QString SieveEditorMainWindow::currentHelpTitle() const { return mMainWidget->sieveEditorMainWidget()->currentHelpTitle(); } QUrl SieveEditorMainWindow::currentHelpUrl() const { return mMainWidget->sieveEditorMainWidget()->currentHelpUrl(); }