sieveeditormainwindow.cpp 17.8 KB
Newer Older
Laurent Montel's avatar
Laurent Montel committed
1
/*
Laurent Montel's avatar
Laurent Montel committed
2
  Copyright (c) 2013-2016 Montel Laurent <montel@kde.org>
Laurent Montel's avatar
Laurent Montel committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

  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 "sieveeditormainwindow.h"
Laurent Montel's avatar
Laurent Montel committed
22
#include "sieveeditormainwidget.h"
Laurent Montel's avatar
Laurent Montel committed
23
#include "sieveeditorconfiguredialog.h"
Laurent Montel's avatar
Laurent Montel committed
24
#include "serversievesettingsdialog.h"
25
#include "sieveserversettings.h"
Laurent Montel's avatar
Laurent Montel committed
26
#include "sieveeditorcentralwidget.h"
27
#include "sieveeditorglobalconfig.h"
Laurent Montel's avatar
Laurent Montel committed
28
#include "sieveeditorbookmarks.h"
Laurent Montel's avatar
Laurent Montel committed
29
#include "PimCommon/KActionMenuChangeCase"
Laurent Montel's avatar
Laurent Montel committed
30

31
#include <KStandardGuiItem>
Laurent Montel's avatar
Laurent Montel committed
32
#include <KSharedConfig>
Laurent Montel's avatar
Laurent Montel committed
33
34
#include <KIconEngine>
#include <KIconLoader>
35

Laurent Montel's avatar
Laurent Montel committed
36
37
#include <KLocalizedString>
#include <KConfigGroup>
38
39
#include <KStandardAction>
#include <KActionCollection>
Laurent Montel's avatar
Laurent Montel committed
40
#include <QAction>
Laurent Montel's avatar
Laurent Montel committed
41
#include <QStatusBar>
Laurent Montel's avatar
Laurent Montel committed
42
#include <QIcon>
Laurent Montel's avatar
Laurent Montel committed
43

Laurent Montel's avatar
Laurent Montel committed
44
#include <QPointer>
Laurent Montel's avatar
Laurent Montel committed
45
#include <QLabel>
Laurent Montel's avatar
Laurent Montel committed
46
#include <QCloseEvent>
47
#include <QNetworkConfigurationManager>
Laurent Montel's avatar
Laurent Montel committed
48

Laurent Montel's avatar
Laurent Montel committed
49
SieveEditorMainWindow::SieveEditorMainWindow()
50
    : KXmlGuiWindow()
Laurent Montel's avatar
Laurent Montel committed
51
{
Laurent Montel's avatar
Laurent Montel committed
52
    mMainWidget = new SieveEditorCentralWidget(this);
53
    connect(mMainWidget, &SieveEditorCentralWidget::configureClicked, this, &SieveEditorMainWindow::slotConfigure);
Laurent Montel's avatar
Laurent Montel committed
54
    connect(mMainWidget->sieveEditorMainWidget(), &SieveEditorMainWidget::updateButtons, this, &SieveEditorMainWindow::slotUpdateButtons);
55
    setCentralWidget(mMainWidget);
Laurent Montel's avatar
Laurent Montel committed
56
57
58
    setupActions();
    setupGUI();
    readConfig();
Laurent Montel's avatar
Laurent Montel committed
59
    initStatusBar();
60
    mNetworkConfigurationManager = new QNetworkConfigurationManager();
61
    connect(mNetworkConfigurationManager, &QNetworkConfigurationManager::onlineStateChanged, this, &SieveEditorMainWindow::slotSystemNetworkOnlineStateChanged);
62

Laurent Montel's avatar
Laurent Montel committed
63
64
    connect(mMainWidget->sieveEditorMainWidget()->tabWidget(), &QTabWidget::currentChanged, this, &SieveEditorMainWindow::slotUpdateActions);
    connect(mMainWidget->sieveEditorMainWidget(), &SieveEditorMainWidget::modeEditorChanged, this, &SieveEditorMainWindow::slotUpdateActions);
65
    slotSystemNetworkOnlineStateChanged(mNetworkConfigurationManager->isOnline());
66
67
68
    connect(mMainWidget->sieveEditorMainWidget(), &SieveEditorMainWidget::undoAvailable, this, &SieveEditorMainWindow::slotUndoAvailable);
    connect(mMainWidget->sieveEditorMainWidget(), &SieveEditorMainWidget::redoAvailable, this, &SieveEditorMainWindow::slotRedoAvailable);
    connect(mMainWidget->sieveEditorMainWidget(), &SieveEditorMainWidget::copyAvailable, this, &SieveEditorMainWindow::slotCopyAvailable);
69
    connect(mMainWidget->sieveEditorMainWidget(), &SieveEditorMainWidget::sieveEditorTabCurrentChanged, this, &SieveEditorMainWindow::slotUpdateActions);
70
    mMainWidget->sieveEditorMainWidget()->refreshList();
Laurent Montel's avatar
Laurent Montel committed
71
72
73
74
}

SieveEditorMainWindow::~SieveEditorMainWindow()
{
75
    KSharedConfig::Ptr config = KSharedConfig::openConfig();
Laurent Montel's avatar
Laurent Montel committed
76
    KConfigGroup group = config->group(QStringLiteral("SieveEditorMainWindow"));
Laurent Montel's avatar
Laurent Montel committed
77
78
    group.writeEntry("Size", size());
    if (SieveEditorGlobalConfig::self()->closeWallet()) {
79
        SieveServerSettings::self()->closeWallet();
Laurent Montel's avatar
Laurent Montel committed
80
    }
Laurent Montel's avatar
Laurent Montel committed
81
82
}

Laurent Montel's avatar
Laurent Montel committed
83
84
85
86
87
88
void SieveEditorMainWindow::initStatusBar()
{
    mStatusBarInfo = new QLabel;
    statusBar()->insertWidget(0, mStatusBarInfo, 4);
}

89
void SieveEditorMainWindow::slotSystemNetworkOnlineStateChanged(bool state)
Laurent Montel's avatar
Laurent Montel committed
90
{
91
    if (state) {
Laurent Montel's avatar
Laurent Montel committed
92
93
94
95
        mStatusBarInfo->setText(i18n("Network is Up."));
    } else {
        mStatusBarInfo->setText(i18n("Network is Down."));
    }
96
    mMainWidget->sieveEditorMainWidget()->setEnabled(state);
Laurent Montel's avatar
Laurent Montel committed
97
    slotUpdateActions();
Laurent Montel's avatar
Laurent Montel committed
98
99
}

Laurent Montel's avatar
Laurent Montel committed
100
101
102
103
void SieveEditorMainWindow::slotUpdateButtons(bool newScriptAction, bool editScriptAction, bool deleteScriptAction, bool desactivateScriptAction)
{
    mDeleteScript->setEnabled(deleteScriptAction);
    mNewScript->setEnabled(newScriptAction);
Laurent Montel's avatar
Laurent Montel committed
104
    mEditScript->setEnabled(editScriptAction);
105
    mDesactivateScript->setEnabled(desactivateScriptAction);
Laurent Montel's avatar
Laurent Montel committed
106
107
}

Laurent Montel's avatar
Laurent Montel committed
108
109
void SieveEditorMainWindow::readConfig()
{
110
    KSharedConfig::Ptr config = KSharedConfig::openConfig();
Laurent Montel's avatar
Laurent Montel committed
111
112
113
114
    KConfigGroup group = KConfigGroup(config, "SieveEditorMainWindow");
    const QSize sizeDialog = group.readEntry("Size", QSize(800, 600));
    if (sizeDialog.isValid()) {
        resize(sizeDialog);
Laurent Montel's avatar
Laurent Montel committed
115
116
117
118
119
    }
}

void SieveEditorMainWindow::setupActions()
{
Laurent Montel's avatar
Laurent Montel committed
120
    KActionCollection *ac = actionCollection();
Laurent Montel's avatar
Laurent Montel committed
121

Laurent Montel's avatar
Laurent Montel committed
122
123
    KStandardAction::quit(this, SLOT(close()), ac);
    KStandardAction::preferences(this, SLOT(slotConfigure()), ac);
Laurent Montel's avatar
Laurent Montel committed
124

Laurent Montel's avatar
Laurent Montel committed
125
    mUploadScript = KStandardAction::save(this, SLOT(slotUploadScript()), ac);
Laurent Montel's avatar
Laurent Montel committed
126
    mUploadScript->setText(i18n("Upload"));
Laurent Montel's avatar
Laurent Montel committed
127
    mUploadScript->setEnabled(false);
Laurent Montel's avatar
Laurent Montel committed
128

Laurent Montel's avatar
Laurent Montel committed
129
    QAction *act = ac->addAction(QStringLiteral("add_server_sieve"), this, SLOT(slotAddServerSieve()));
130
    act->setText(i18n("Add Sieve Server..."));
Laurent Montel's avatar
Laurent Montel committed
131

Laurent Montel's avatar
Laurent Montel committed
132
    mDeleteScript = ac->addAction(QStringLiteral("delete_script"), this, SLOT(slotDeleteScript()));
Laurent Montel's avatar
Laurent Montel committed
133
    mDeleteScript->setText(i18n("Delete Script"));
Laurent Montel's avatar
Laurent Montel committed
134
    ac->setDefaultShortcut(mDeleteScript, QKeySequence(Qt::Key_Delete));
Laurent Montel's avatar
Laurent Montel committed
135
    mDeleteScript->setEnabled(false);
Laurent Montel's avatar
Laurent Montel committed
136

Laurent Montel's avatar
Laurent Montel committed
137
    mNewScript = ac->addAction(QStringLiteral("create_new_script"), this, SLOT(slotCreateNewScript()));
Laurent Montel's avatar
Laurent Montel committed
138
    ac->setDefaultShortcut(mNewScript, QKeySequence(Qt::CTRL + Qt::Key_N));
Laurent Montel's avatar
Laurent Montel committed
139
140
    mNewScript->setText(i18n("Create New Script..."));
    mNewScript->setEnabled(false);
Laurent Montel's avatar
Laurent Montel committed
141

Laurent Montel's avatar
Laurent Montel committed
142
    mEditScript = ac->addAction(QStringLiteral("edit_script"), this, SLOT(slotEditScript()));
143
    mEditScript->setText(i18n("Edit Script..."));
Laurent Montel's avatar
Laurent Montel committed
144
    mEditScript->setEnabled(false);
145

Laurent Montel's avatar
Laurent Montel committed
146
    mDesactivateScript = ac->addAction(QStringLiteral("desactivate_script"), this, SLOT(slotDesactivateScript()));
Yuri Chornoivan's avatar
Yuri Chornoivan committed
147
    mDesactivateScript->setText(i18n("Deactivate Script"));
148
    mDesactivateScript->setEnabled(false);
Laurent Montel's avatar
Laurent Montel committed
149

Laurent Montel's avatar
Laurent Montel committed
150
    mRefreshList = ac->addAction(QStringLiteral("refresh_list"), this, SLOT(slotRefreshList()));
Laurent Montel's avatar
Laurent Montel committed
151
    mRefreshList->setText(i18n("Refresh List"));
Laurent Montel's avatar
Laurent Montel committed
152
    mRefreshList->setIcon(QIcon::fromTheme(QStringLiteral("view-refresh")));
Laurent Montel's avatar
Laurent Montel committed
153
    ac->setDefaultShortcut(mRefreshList, QKeySequence(Qt::Key_F5));
154

Laurent Montel's avatar
Laurent Montel committed
155
    mGoToLine = ac->addAction(QStringLiteral("gotoline"), mMainWidget->sieveEditorMainWidget(), SLOT(slotGoToLine()));
156
    mGoToLine->setText(i18n("Go to Line..."));
Laurent Montel's avatar
Laurent Montel committed
157
    mGoToLine->setIcon(QIcon::fromTheme(QStringLiteral("go-jump")));
Laurent Montel's avatar
Laurent Montel committed
158
    ac->setDefaultShortcut(mGoToLine, QKeySequence(Qt::CTRL + Qt::Key_G));
159
    mGoToLine->setEnabled(false);
160

Laurent Montel's avatar
Laurent Montel committed
161
162
163
164
    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);
Laurent Montel's avatar
Laurent Montel committed
165
166
167
    mCopyAction = KStandardAction::copy(mMainWidget->sieveEditorMainWidget(), SLOT(slotCopy()), ac);
    mPasteAction = KStandardAction::paste(mMainWidget->sieveEditorMainWidget(), SLOT(slotPaste()), ac);
    mCutAction = KStandardAction::cut(mMainWidget->sieveEditorMainWidget(), SLOT(slotCut()), ac);
Laurent Montel's avatar
Laurent Montel committed
168
    mSelectAllAction = KStandardAction::selectAll(mMainWidget->sieveEditorMainWidget(), SLOT(slotSelectAll()), ac);
Laurent Montel's avatar
Laurent Montel committed
169
    mSaveAsAction = KStandardAction::saveAs(mMainWidget->sieveEditorMainWidget(), SLOT(slotSaveAs()), ac);
170

Laurent Montel's avatar
Laurent Montel committed
171
    mImportAction = ac->addAction(QStringLiteral("import_script"), mMainWidget->sieveEditorMainWidget(), SLOT(slotImport()));
172
173
174
    mImportAction->setText(i18n("Import..."));
    mImportAction->setEnabled(false);

Laurent Montel's avatar
Laurent Montel committed
175
    mShareAction = ac->addAction(QStringLiteral("share_script"), mMainWidget->sieveEditorMainWidget(), SLOT(slotShareScript()));
176
    mShareAction->setText(i18n("Share..."));
Laurent Montel's avatar
Laurent Montel committed
177
178
    const QStringList overlays = QStringList() << QStringLiteral("list-add");
    mShareAction->setIcon(QIcon(new KIconEngine(QStringLiteral("get-hot-new-stuff"), KIconLoader::global(), overlays)));
179
180
    mShareAction->setEnabled(false);

Laurent Montel's avatar
Laurent Montel committed
181
    mSpellCheckAction = ac->addAction(QStringLiteral("check_spelling"), mMainWidget->sieveEditorMainWidget(), SLOT(slotCheckSpelling()));
182
183
184
185
    mSpellCheckAction->setIcon(QIcon::fromTheme(QStringLiteral("tools-check-spelling")));
    mSpellCheckAction->setText(i18n("Check Spelling..."));
    mSpellCheckAction->setEnabled(false);

Laurent Montel's avatar
Laurent Montel committed
186
    mCheckSyntaxAction = ac->addAction(QStringLiteral("check_syntax"), mMainWidget->sieveEditorMainWidget(), SLOT(slotCheckSyntax()));
Laurent Montel's avatar
Laurent Montel committed
187
188
189
    mCheckSyntaxAction->setText(i18n("Check Syntax"));
    mCheckSyntaxAction->setEnabled(false);

Laurent Montel's avatar
Laurent Montel committed
190
    mAutoGenerateScriptAction = ac->addAction(QStringLiteral("autogenerate_script"), mMainWidget->sieveEditorMainWidget(), SLOT(slotAutoGenerateScript()));
Laurent Montel's avatar
Laurent Montel committed
191
192
    mAutoGenerateScriptAction->setText(i18n("Autogenerate Script..."));
    mAutoGenerateScriptAction->setEnabled(false);
193

Laurent Montel's avatar
Laurent Montel committed
194
    mCommentAction = ac->addAction(QStringLiteral("comment_code"), mMainWidget->sieveEditorMainWidget(), SLOT(slotComment()));
Laurent Montel's avatar
Laurent Montel committed
195
    ac->setDefaultShortcut(mCommentAction, Qt::CTRL + Qt::Key_D);
196
197
    mCommentAction->setText(i18n("Comment"));

Laurent Montel's avatar
Laurent Montel committed
198
    mUncommentAction = ac->addAction(QStringLiteral("uncomment_code"), mMainWidget->sieveEditorMainWidget(), SLOT(slotUncomment()));
Laurent Montel's avatar
Laurent Montel committed
199
    ac->setDefaultShortcut(mUncommentAction, Qt::CTRL + Qt::SHIFT + Qt::Key_D);
200
    mUncommentAction->setText(i18n("Uncomment"));
Laurent Montel's avatar
Laurent Montel committed
201

Laurent Montel's avatar
Laurent Montel committed
202
203
204
    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);
Laurent Montel's avatar
Laurent Montel committed
205
    ac->setDefaultShortcut(mZoomInAction, QKeySequence(Qt::CTRL + Qt::Key_Plus));
Laurent Montel's avatar
Laurent Montel committed
206

Laurent Montel's avatar
Laurent Montel committed
207
208
209
    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);
Laurent Montel's avatar
Laurent Montel committed
210
    ac->setDefaultShortcut(mZoomOutAction, QKeySequence(Qt::CTRL + Qt::Key_Minus));
Laurent Montel's avatar
Laurent Montel committed
211
212

    mZoomResetAction = ac->addAction(QStringLiteral("zoom_reset"), mMainWidget->sieveEditorMainWidget(), SLOT(slotZoomReset()));
Laurent Montel's avatar
Laurent Montel committed
213
    ac->setDefaultShortcut(mZoomResetAction, QKeySequence(Qt::CTRL + Qt::Key_0));
Laurent Montel's avatar
Laurent Montel committed
214
    mZoomResetAction->setText(i18nc("Reset the zoom", "Reset"));
Laurent Montel's avatar
Laurent Montel committed
215

Laurent Montel's avatar
Laurent Montel committed
216
217
218
219
220
221
222
    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);
Laurent Montel's avatar
Laurent Montel committed
223

Laurent Montel's avatar
Laurent Montel committed
224
225
226
227
    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);
228
229
230

    mDebugSieveScriptAction = ac->addAction(QStringLiteral("debug_sieve"), mMainWidget->sieveEditorMainWidget(), SLOT(slotDebugSieveScript()));
    mDebugSieveScriptAction->setText(i18n("Debug Sieve Script..."));
Laurent Montel's avatar
Laurent Montel committed
231
    ac->setDefaultShortcut(mDebugSieveScriptAction, QKeySequence(Qt::SHIFT + Qt::ALT + Qt::Key_D));
Laurent Montel's avatar
Laurent Montel committed
232
233
234
235

    mWrapTextAction = new QAction(i18n("Wordwarp"), this);
    mWrapTextAction->setCheckable(true);
    ac->addAction(QStringLiteral("wordwrap"), mWrapTextAction);
236
    connect(mWrapTextAction, &QAction::triggered, mMainWidget->sieveEditorMainWidget(), &SieveEditorMainWidget::slotWordWrap);
237
238
239
240

    mPrintAction = KStandardAction::print(mMainWidget->sieveEditorMainWidget(), SLOT(slotPrint()), ac);

    mPrintPreviewAction = KStandardAction::printPreview(mMainWidget->sieveEditorMainWidget(), SLOT(slotPrintPreview()), ac);
Laurent Montel's avatar
Laurent Montel committed
241
242
243
244
}

void SieveEditorMainWindow::slotRefreshList()
{
245
    if (mNetworkConfigurationManager->isOnline()) {
Laurent Montel's avatar
Laurent Montel committed
246
        mMainWidget->sieveEditorMainWidget()->refreshList();
Laurent Montel's avatar
Laurent Montel committed
247
    }
248
249
}

Laurent Montel's avatar
Laurent Montel committed
250
void SieveEditorMainWindow::slotUploadScript()
Laurent Montel's avatar
Laurent Montel committed
251
{
Laurent Montel's avatar
Laurent Montel committed
252
    mMainWidget->sieveEditorMainWidget()->uploadScript();
Laurent Montel's avatar
Laurent Montel committed
253
254
}

255
256
void SieveEditorMainWindow::slotDesactivateScript()
{
Laurent Montel's avatar
Laurent Montel committed
257
    mMainWidget->sieveEditorMainWidget()->desactivateScript();
Laurent Montel's avatar
Laurent Montel committed
258
259
}

Laurent Montel's avatar
Laurent Montel committed
260
261
void SieveEditorMainWindow::slotEditScript()
{
Laurent Montel's avatar
Laurent Montel committed
262
    mMainWidget->sieveEditorMainWidget()->editScript();
Laurent Montel's avatar
Laurent Montel committed
263
264
}

Laurent Montel's avatar
Laurent Montel committed
265
266
void SieveEditorMainWindow::slotCreateNewScript()
{
Laurent Montel's avatar
Laurent Montel committed
267
    mMainWidget->sieveEditorMainWidget()->createNewScript();
Laurent Montel's avatar
Laurent Montel committed
268
269
270
271
}

void SieveEditorMainWindow::slotDeleteScript()
{
Laurent Montel's avatar
Laurent Montel committed
272
    mMainWidget->sieveEditorMainWidget()->deleteScript();
Laurent Montel's avatar
Laurent Montel committed
273
274
}

Laurent Montel's avatar
Laurent Montel committed
275
void SieveEditorMainWindow::closeEvent(QCloseEvent *e)
276
{
Laurent Montel's avatar
Laurent Montel committed
277
    if (mMainWidget->sieveEditorMainWidget()->needToSaveScript()) {
Laurent Montel's avatar
Laurent Montel committed
278
279
280
281
282
        e->ignore();
        return;
    } else {
        e->accept();
    }
283
284
285
286
}

void SieveEditorMainWindow::slotConfigure()
{
Laurent Montel's avatar
Laurent Montel committed
287
288
    QPointer<SieveEditorConfigureDialog> dlg = new SieveEditorConfigureDialog(this);
    if (dlg->exec()) {
289
        dlg->saveServerSieveConfig();
Laurent Montel's avatar
Laurent Montel committed
290
        mMainWidget->sieveEditorMainWidget()->updateServerList();
Laurent Montel's avatar
Laurent Montel committed
291
292
293
294
295
296
    }
    delete dlg;
}

void SieveEditorMainWindow::slotAddServerSieve()
{
Laurent Montel's avatar
Laurent Montel committed
297
    QPointer<ServerSieveSettingsDialog> dlg = new ServerSieveSettingsDialog(this);
Laurent Montel's avatar
Laurent Montel committed
298
    if (dlg->exec()) {
Laurent Montel's avatar
Laurent Montel committed
299
300
        const SieveEditorUtil::SieveServerConfig conf = dlg->serverSieveConfig();
        SieveEditorUtil::addServerSieveConfig(conf);
Laurent Montel's avatar
Laurent Montel committed
301
        mMainWidget->sieveEditorMainWidget()->updateServerList();
Laurent Montel's avatar
Laurent Montel committed
302
303
    }
    delete dlg;
304
}
Laurent Montel's avatar
Laurent Montel committed
305
306
307

void SieveEditorMainWindow::slotUpdateActions()
{
Laurent Montel's avatar
Laurent Montel committed
308
    const bool hasPage = (mMainWidget->sieveEditorMainWidget()->tabWidget()->count() > 0);
Laurent Montel's avatar
Laurent Montel committed
309
    mUploadScript->setEnabled(hasPage);
310
    const bool editActionEnabled = (hasPage && mMainWidget->sieveEditorMainWidget()->isTextEditor());
311
    const bool hasActionInHtmlModeToo = (hasPage && mMainWidget->sieveEditorMainWidget()->pageMode() == KSieveUi::SieveEditorWidget::TextMode);
Laurent Montel's avatar
Laurent Montel committed
312
313
314
    mGoToLine->setEnabled(editActionEnabled);
    mFindAction->setEnabled(editActionEnabled);
    mReplaceAction->setEnabled(editActionEnabled);
315
316
    mUndoAction->setEnabled(editActionEnabled && mMainWidget->sieveEditorMainWidget()->isUndoAvailable());
    mRedoAction->setEnabled(editActionEnabled && mMainWidget->sieveEditorMainWidget()->isRedoAvailable());
Laurent Montel's avatar
Laurent Montel committed
317

Laurent Montel's avatar
Laurent Montel committed
318
    mCopyAction->setEnabled(hasActionInHtmlModeToo && mMainWidget->sieveEditorMainWidget()->hasSelection());
319
320
    mPasteAction->setEnabled(editActionEnabled);
    mCutAction->setEnabled(editActionEnabled && mMainWidget->sieveEditorMainWidget()->hasSelection());
Laurent Montel's avatar
Laurent Montel committed
321

322
    mSelectAllAction->setEnabled(hasActionInHtmlModeToo);
Laurent Montel's avatar
Laurent Montel committed
323

Laurent Montel's avatar
Laurent Montel committed
324
    mUploadScript->setEnabled(hasPage && !mNetworkIsDown);
Laurent Montel's avatar
Laurent Montel committed
325
    mRefreshList->setEnabled(!mNetworkIsDown);
Laurent Montel's avatar
Laurent Montel committed
326
    mSaveAsAction->setEnabled(hasPage);
327
328
    mImportAction->setEnabled(hasPage);
    mShareAction->setEnabled(hasPage && !mNetworkIsDown);
329
    mSpellCheckAction->setEnabled(editActionEnabled);
Laurent Montel's avatar
Laurent Montel committed
330
331
    mCheckSyntaxAction->setEnabled(editActionEnabled && !mNetworkIsDown);
    mAutoGenerateScriptAction->setEnabled(editActionEnabled);
332
333
334
    mCommentAction->setEnabled(editActionEnabled);
    mUncommentAction->setEnabled(editActionEnabled);
    mMenuChangeCaseAction->setEnabled(editActionEnabled);
335
336
337
    mZoomInAction->setEnabled(hasActionInHtmlModeToo);
    mZoomOutAction->setEnabled(hasActionInHtmlModeToo);
    mZoomResetAction->setEnabled(hasActionInHtmlModeToo);
Laurent Montel's avatar
Laurent Montel committed
338

339
    mBookmarkMenu->setEnabled(hasActionInHtmlModeToo);
340
    mDebugSieveScriptAction->setEnabled(editActionEnabled);
341
    mWrapTextAction->setEnabled(editActionEnabled);
Laurent Montel's avatar
Laurent Montel committed
342
    mWrapTextAction->setChecked(mMainWidget->sieveEditorMainWidget()->isWordWrap());
Laurent Montel's avatar
Laurent Montel committed
343

Laurent Montel's avatar
Laurent Montel committed
344
345
    mPrintAction->setEnabled(editActionEnabled && mMainWidget->sieveEditorMainWidget()->printSupportEnabled());
    mPrintPreviewAction->setEnabled(editActionEnabled && mMainWidget->sieveEditorMainWidget()->printSupportEnabled());
Laurent Montel's avatar
Laurent Montel committed
346
347
}

348
349
void SieveEditorMainWindow::slotUndoAvailable(bool b)
{
Laurent Montel's avatar
Laurent Montel committed
350
    const bool hasPage = (mMainWidget->sieveEditorMainWidget()->tabWidget()->count() > 0);
351
352
353
354
355
356
    const bool editActionEnabled = (hasPage && mMainWidget->sieveEditorMainWidget()->pageMode() == KSieveUi::SieveEditorWidget::TextMode);
    mUndoAction->setEnabled(editActionEnabled && b);
}

void SieveEditorMainWindow::slotRedoAvailable(bool b)
{
Laurent Montel's avatar
Laurent Montel committed
357
    const bool hasPage = (mMainWidget->sieveEditorMainWidget()->tabWidget()->count() > 0);
358
359
360
361
    const bool editActionEnabled = (hasPage && mMainWidget->sieveEditorMainWidget()->pageMode() == KSieveUi::SieveEditorWidget::TextMode);
    mRedoAction->setEnabled(editActionEnabled && b);
}

Laurent Montel's avatar
Laurent Montel committed
362
363
void SieveEditorMainWindow::slotCopyAvailable(bool b)
{
Laurent Montel's avatar
Laurent Montel committed
364
    const bool hasPage = (mMainWidget->sieveEditorMainWidget()->tabWidget()->count() > 0);
Laurent Montel's avatar
Laurent Montel committed
365
366
    const bool editActionEnabled = (hasPage && mMainWidget->sieveEditorMainWidget()->pageMode() == KSieveUi::SieveEditorWidget::TextMode);
    mCopyAction->setEnabled(editActionEnabled && b);
Laurent Montel's avatar
Laurent Montel committed
367
    mCutAction->setEnabled(editActionEnabled && b);
Laurent Montel's avatar
Laurent Montel committed
368
}
Laurent Montel's avatar
Laurent Montel committed
369

Laurent Montel's avatar
Laurent Montel committed
370
void SieveEditorMainWindow::slotOpenBookmarkUrl(const QUrl &url)
Laurent Montel's avatar
Laurent Montel committed
371
{
Laurent Montel's avatar
Laurent Montel committed
372
    mMainWidget->sieveEditorMainWidget()->openBookmarkUrl(url);
Laurent Montel's avatar
Laurent Montel committed
373
374
375
376
377
378
379
380
381
382
383
}

QString SieveEditorMainWindow::currentHelpTitle() const
{
    return mMainWidget->sieveEditorMainWidget()->currentHelpTitle();
}

QUrl SieveEditorMainWindow::currentHelpUrl() const
{
    return mMainWidget->sieveEditorMainWidget()->currentHelpUrl();
}