29 #include <QHBoxLayout>
30 #include <QInputDialog>
32 #include <QStackedWidget>
33 #include <QTextCursor>
34 #include <QTextDocument>
35 #include <QTextDocumentFragment>
37 #include <QPrintDialog>
41 #include <QAbstractTextDocumentLayout>
42 #include <QDBusConnection>
45 #include <akonadi/control.h>
46 #include <akonadi/collectiondeletejob.h>
47 #include <akonadi/collectioncreatejob.h>
48 #include <akonadi/changerecorder.h>
49 #include <akonadi/entitydisplayattribute.h>
50 #include <akonadi/entitytreeview.h>
51 #include <akonadi/etmviewstatesaver.h>
52 #include <akonadi/item.h>
53 #include <Akonadi/ItemCreateJob>
54 #include <Akonadi/ItemDeleteJob>
55 #include <akonadi/itemfetchjob.h>
56 #include <akonadi/itemfetchscope.h>
58 #include "akonadi/entityorderproxymodel.h"
59 #include "akonadi_next/note.h"
60 #include "akonadi_next/notecreatorandselector.h"
63 #include <grantlee/template.h>
64 #include <grantlee/engine.h>
65 #include <grantlee/context.h>
69 #include <KActionCollection>
70 #include <KBookmarkMenu>
71 #include <KFileDialog>
73 #include <KFindDialog>
75 #include <KMessageBox>
76 #include <KReplaceDialog>
77 #include <kselectionproxymodel.h>
78 #include <KStandardDirs>
79 #include <KTextBrowser>
80 #include <KGlobalSettings>
81 #include <KXMLGUIClient>
83 #include <KPrintPreview>
86 #include <KMime/KMimeMessage>
107 #ifndef KDE_USE_FINAL
108 Q_DECLARE_METATYPE(QTextDocument*)
109 Q_DECLARE_METATYPE(QTextCursor)
111 using namespace Akonadi;
112 using namespace Grantlee;
115 :
QWidget( parent, f ), m_xmlGuiClient( xmlGuiClient )
117 Akonadi::Control::widgetNeedsAkonadi(
this );
119 KConfigGroup migrationCfg( KGlobal::config(),
"General" );
120 const bool autoCreate = migrationCfg.readEntry(
"AutoCreateResourceOnStart",
true );
121 migrationCfg.writeEntry(
"AutoCreateResourceOnStart", autoCreate);
128 m_splitter =
new QSplitter(
this );
130 m_splitter->setStretchFactor(1, 1);
131 m_splitter->setOpaqueResize( KGlobalSettings::opaqueResize() );
133 QHBoxLayout *layout =
new QHBoxLayout(
this );
134 layout->setMargin( 0 );
137 m_templateEngine =
new Engine(
this);
138 m_templateEngine->setPluginPaths( KStd.findDirs(
"lib", QString() ) );
140 m_loader = FileSystemTemplateLoader::Ptr(
new FileSystemTemplateLoader() );
141 m_loader->setTemplateDirs( KStd.findDirs(
"data", QLatin1String(
"kjots/themes" ) ) );
142 m_loader->setTheme( QLatin1String(
"default" ) );
144 m_templateEngine->addTemplateLoader( m_loader );
148 ItemFetchScope scope;
149 scope.fetchFullPayload(
true );
150 scope.fetchAttribute< EntityDisplayAttribute >();
153 ChangeRecorder *monitor =
new ChangeRecorder(
this );
154 monitor->fetchCollection(
true );
155 monitor->setItemFetchScope( scope );
156 monitor->setCollectionMonitored( Collection::root() );
157 monitor->setMimeTypeMonitored( Akonotes::Note::mimeType() );
159 m_kjotsModel =
new KJotsModel( monitor,
this );
162 m_sortProxyModel->setSourceModel( m_kjotsModel );
164 m_orderProxy =
new EntityOrderProxyModel(
this );
165 m_orderProxy->setSourceModel( m_sortProxyModel );
167 KConfigGroup cfg( KGlobal::config(),
"KJotsEntityOrder" );
169 m_orderProxy->setOrderConfig( cfg );
171 treeview->setModel( m_orderProxy );
172 treeview->setSelectionMode( QAbstractItemView::ExtendedSelection );
173 treeview->setEditTriggers( QAbstractItemView::DoubleClicked );
175 connect( treeview->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SLOT(selectionChanged(QItemSelection,QItemSelection)) );
177 selProxy =
new KSelectionProxyModel( treeview->selectionModel(), this );
178 selProxy->setSourceModel( treeview->model() );
181 connect( selProxy, SIGNAL(dataChanged(QModelIndex,QModelIndex)), SLOT(
renderSelection()) );
182 connect( selProxy, SIGNAL(rowsInserted(QModelIndex,
int,
int)), SLOT(
renderSelection()) );
183 connect( selProxy, SIGNAL(rowsRemoved(QModelIndex,
int,
int)), SLOT(
renderSelection()) );
186 stackedWidget =
new QStackedWidget( m_splitter );
188 KActionCollection *actionCollection = xmlGuiClient->actionCollection();
190 editor =
new KJotsEdit( treeview->selectionModel(), stackedWidget );
191 editor->createActions( actionCollection );
192 stackedWidget->addWidget( editor );
194 layout->addWidget( m_splitter );
196 browser =
new KJotsBrowser( treeview->selectionModel(), stackedWidget );
197 stackedWidget->addWidget( browser );
198 stackedWidget->setCurrentWidget( browser );
203 action = actionCollection->addAction( QLatin1String(
"go_next_book") );
204 action->setText( i18n(
"Next Book" ) );
205 action->setIcon( KIcon( QLatin1String(
"go-down") ) );
206 action->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_D ) );
207 connect( action, SIGNAL(triggered()), SLOT(
nextBook()) );
210 action = actionCollection->addAction( QLatin1String(
"go_prev_book") );
211 action->setText( i18n(
"Previous Book" ) );
212 action->setIcon( KIcon( QLatin1String(
"go-up") ) );
213 action->setShortcut( QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_D ) );
214 connect( action, SIGNAL(triggered()), SLOT(
prevBook()) );
217 action = actionCollection->addAction( QLatin1String(
"go_next_page") );
218 action->setText( i18n(
"Next Page" ) );
219 action->setIcon( KIcon( QLatin1String(
"go-next") ) );
220 action->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_PageDown ) );
221 connect( action, SIGNAL(triggered()), SLOT(
nextPage()));
224 action = actionCollection->addAction( QLatin1String(
"go_prev_page") );
225 action->setText( i18n(
"Previous Page" ) );
226 action->setIcon( KIcon( QLatin1String(
"go-previous") ) );
227 action->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_PageUp ) );
228 connect( action, SIGNAL(triggered()), SLOT(
prevPage()) );
231 action = actionCollection->addAction( QLatin1String(
"new_page") );
232 action->setText( i18n(
"&New Page" ) );
233 action->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_N ) );
234 action->setIcon( KIcon( QLatin1String(
"document-new") ) );
235 connect( action, SIGNAL(triggered()), SLOT(
newPage()) );
237 action = actionCollection->addAction(QLatin1String(
"new_book"));
238 action->setText( i18n(
"New &Book..." ) );
239 action->setShortcut( QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_N ) );
240 action->setIcon( KIcon( QLatin1String(
"address-book-new") ) );
241 connect( action, SIGNAL(triggered()), SLOT(
newBook()) );
243 action = actionCollection->addAction( QLatin1String(
"del_page") );
244 action->setText( i18n(
"&Delete Page" ) );
245 action->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_Delete ) );
246 action->setIcon( KIcon( QLatin1String(
"edit-delete-page") ) );
247 connect( action, SIGNAL(triggered()), SLOT(
deletePage()) );
249 action = actionCollection->addAction( QLatin1String(
"del_folder") );
250 action->setText( i18n(
"Delete Boo&k" ) );
251 action->setShortcut( QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_Delete ) );
252 action->setIcon( KIcon( QLatin1String(
"edit-delete") ) );
253 connect( action, SIGNAL(triggered()), SLOT(
deleteBook()) );
255 action = actionCollection->addAction( QLatin1String(
"del_mult") );
256 action->setText( i18n(
"Delete Selected" ) );
257 action->setIcon( KIcon( QLatin1String(
"edit-delete") ) );
260 action = actionCollection->addAction( QLatin1String(
"manual_save") );
261 action->setText( i18n(
"Manual Save" ) );
262 action->setIcon( KIcon( QLatin1String(
"document-save") ) );
263 action->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_S ) );
265 action = actionCollection->addAction( QLatin1String(
"auto_bullet") );
266 action->setText( i18n(
"Auto Bullets" ) );
267 action->setIcon( KIcon( QLatin1String(
"format-list-unordered") ) );
268 action->setCheckable(
true );
270 action = actionCollection->addAction( QLatin1String(
"auto_decimal") );
271 action->setText( i18n(
"Auto Decimal List" ) );
272 action->setIcon( KIcon( QLatin1String(
"format-list-ordered") ) );
273 action->setCheckable(
true );
275 action = actionCollection->addAction( QLatin1String(
"manage_link") );
276 action->setText( i18n(
"Link" ) );
277 action->setIcon( KIcon( QLatin1String(
"insert-link") ) );
279 action = actionCollection->addAction( QLatin1String(
"insert_checkmark") );
280 action->setText( i18n(
"Insert Checkmark" ) );
281 action->setIcon( KIcon( QLatin1String(
"checkmark") ) );
282 action->setEnabled(
false );
284 action = actionCollection->addAction( QLatin1String(
"rename_entry") );
285 action->setText( i18n(
"Rename..." ) );
286 action->setIcon( KIcon( QLatin1String(
"edit-rename") ) );
287 action->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_M ) );
289 action = actionCollection->addAction( QLatin1String(
"insert_date") );
290 action->setText( i18n(
"Insert Date" ) );
291 action->setShortcut( QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_I ) );
292 action->setIcon( KIcon( QLatin1String(
"view-calendar-time-spent") ) );
294 action = actionCollection->addAction( QLatin1String(
"change_color") );
295 action->setIcon( KIcon( QLatin1String(
"format-fill-color") ) );
296 action->setText( i18n(
"Change Color..." ) );
298 action = actionCollection->addAction( QLatin1String(
"copy_link_address") );
299 action->setText( i18n(
"Copy Link Address" ) );
301 action = actionCollection->addAction( QLatin1String(
"lock") );
302 action->setText(i18n(
"Lock Selected" ) );
303 action->setIcon( KIcon( QLatin1String(
"emblem-locked") ) );
304 connect( action, SIGNAL(triggered()), SLOT(actionLock()) );
306 action = actionCollection->addAction( QLatin1String(
"unlock") );
307 action->setText( i18n(
"Unlock Selected" ) );
308 action->setIcon( KIcon( QLatin1String(
"emblem-unlocked") ) );
309 connect( action, SIGNAL(triggered()), SLOT(actionUnlock()) );
311 action = actionCollection->addAction( QLatin1String(
"sort_children_alpha") );
312 action->setText( i18n(
"Sort children alphabetically" ) );
313 connect( action, SIGNAL(triggered()), SLOT(actionSortChildrenAlpha()) );
315 action = actionCollection->addAction( QLatin1String(
"sort_children_by_date") );
316 action->setText( i18n(
"Sort children by creation date" ) );
317 connect( action, SIGNAL(triggered()), SLOT(actionSortChildrenByDate()) );
319 action = KStandardAction::cut( editor, SLOT(cut()), actionCollection );
320 connect( editor, SIGNAL(copyAvailable(
bool)), action, SLOT(setEnabled(
bool)) );
321 action->setEnabled(
false );
323 action = KStandardAction::copy(
this, SLOT(copy()), actionCollection );
324 connect( editor, SIGNAL(copyAvailable(
bool)), action, SLOT(setEnabled(
bool)) );
325 connect( browser, SIGNAL(copyAvailable(
bool)), action, SLOT(setEnabled(
bool)) );
326 action->setEnabled(
false );
328 KStandardAction::pasteText( editor, SLOT(paste()), actionCollection );
330 KStandardAction::undo( editor, SLOT(undo()), actionCollection );
331 KStandardAction::redo( editor, SLOT(redo()), actionCollection );
332 KStandardAction::selectAll( editor, SLOT(selectAll()), actionCollection );
334 action = actionCollection->addAction( QLatin1String(
"copyIntoTitle") );
335 action->setText( i18n(
"Copy &into Page Title" ) );
336 action->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_T ) );
337 action->setIcon( KIcon( QLatin1String(
"edit-copy") ) );
338 connect( action, SIGNAL(triggered()), SLOT(copySelectionToTitle()) );
339 connect( editor, SIGNAL(copyAvailable(
bool)), action, SLOT(setEnabled(
bool)) );
340 action->setEnabled(
false );
342 action = actionCollection->addAction( QLatin1String(
"paste_plain_text") );
343 action->setText( i18nc(
"@action Paste the text in the clipboard without rich text formatting.",
"Paste Plain Text" ) );
344 connect( action, SIGNAL(triggered()), editor, SLOT(pastePlainText()) );
346 KStandardAction::preferences(
this, SLOT(configure()), actionCollection );
348 bookmarkMenu = actionCollection->add<KActionMenu>( QLatin1String(
"bookmarks") );
349 bookmarkMenu->setText( i18n(
"&Bookmarks" ) );
352 KBookmarkManager::managerForFile( KStandardDirs::locateLocal(
"data",QLatin1String(
"kjots/bookmarks.xml") ), QLatin1String(
"kjots") ),
353 bookmarks, bookmarkMenu->menu(), actionCollection );
357 KAction *bm_action = qobject_cast<KAction *>(actionCollection->action(QLatin1String(
"add_bookmark")));
359 bm_action->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_B );
361 KStandardAction::find(
this, SLOT(onShowSearch()), actionCollection );
362 action = KStandardAction::findNext(
this, SLOT(onRepeatSearch()), actionCollection );
363 action->setEnabled(
false);
364 KStandardAction::replace(
this, SLOT(onShowReplace()), actionCollection );
366 action = actionCollection->addAction( QLatin1String(
"save_to") );
367 action->setText( i18n(
"Rename..." ) );
368 action->setIcon( KIcon( QLatin1String(
"edit-rename") ) );
369 action->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_M ) );
371 KActionMenu *exportMenu = actionCollection->add<KActionMenu>( QLatin1String(
"save_to") );
372 exportMenu->setText( i18n(
"Export" ) );
373 exportMenu->setIcon( KIcon( QLatin1String(
"document-export") ) );
375 action = actionCollection->addAction( QLatin1String(
"save_to_ascii") );
376 action->setText( i18n(
"To Text File..." ) );
377 action->setIcon( KIcon( QLatin1String(
"text-plain") ) );
379 exportMenu->menu()->addAction( action );
381 action = actionCollection->addAction( QLatin1String(
"save_to_html") );
382 action->setText( i18n(
"To HTML File..." ) );
383 action->setIcon( KIcon( QLatin1String(
"text-html") ) );
385 exportMenu->menu()->addAction( action );
387 action = actionCollection->addAction( QLatin1String(
"save_to_book") );
388 action->setText( i18n(
"To Book File..." ) );
389 action->setIcon( KIcon( QLatin1String(
"x-office-address-book") ) );
391 exportMenu->menu()->addAction( action );
393 KStandardAction::print(
this, SLOT(
printSelection()), actionCollection);
401 QTimer::singleShot( 0,
this, SLOT(delayedInitialization()) );
403 connect( treeview->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SLOT(
updateMenu()) );
404 connect( treeview->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SLOT(
updateCaption()) );
406 connect( m_kjotsModel, SIGNAL(modelAboutToBeReset()), SLOT(saveState()));
407 connect( m_kjotsModel, SIGNAL(modelReset()), SLOT(restoreState()));
411 QDBusConnection::sessionBus().registerObject( QLatin1String(
"/KJotsWidget"),
this, QDBusConnection::ExportScriptableContents );
419 void KJotsWidget::restoreState()
421 ETMViewStateSaver *saver =
new ETMViewStateSaver;
422 saver->setView( treeview );
423 KConfigGroup cfg( KGlobal::config(),
"TreeState" );
424 saver->restoreState( cfg );
427 void KJotsWidget::saveState()
429 ETMViewStateSaver saver;
430 saver.setView( treeview );
431 KConfigGroup cfg( KGlobal::config(),
"TreeState" );
432 saver.saveState( cfg );
436 void KJotsWidget::delayedInitialization()
443 searchDialog =
new KFindDialog (
this, 0, QStringList(),
false );
444 QGridLayout *layout =
new QGridLayout(searchDialog->findExtension());
445 layout->setMargin(0);
446 searchAllPages =
new QCheckBox(i18n(
"Search all pages"), searchDialog->findExtension());
447 layout->addWidget(searchAllPages, 0, 0);
449 connect(searchDialog, SIGNAL(okClicked()),
this, SLOT(onStartSearch()) );
450 connect(searchDialog, SIGNAL(cancelClicked()),
this, SLOT(onEndSearch()) );
451 connect(treeview->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SLOT(onUpdateSearch()) );
452 connect(searchDialog, SIGNAL(optionsChanged()), SLOT(onUpdateSearch()) );
453 connect(searchAllPages, SIGNAL(stateChanged(
int)), SLOT(onUpdateSearch()) );
455 replaceDialog =
new KReplaceDialog (
this, 0, searchHistory, replaceHistory,
false );
456 QGridLayout *layout2 =
new QGridLayout(replaceDialog->findExtension());
457 layout2->setMargin(0);
458 replaceAllPages =
new QCheckBox(i18n(
"Search all pages"), replaceDialog->findExtension());
459 layout2->addWidget(replaceAllPages, 0, 0);
461 connect(replaceDialog, SIGNAL(okClicked()),
this, SLOT(onStartReplace()) );
462 connect(replaceDialog, SIGNAL(cancelClicked()),
this, SLOT(onEndReplace()) );
463 connect(replaceDialog, SIGNAL(optionsChanged()), SLOT(onUpdateReplace()) );
464 connect(replaceAllPages, SIGNAL(stateChanged(
int)), SLOT(onUpdateReplace()) );
477 KActionCollection *actionCollection = m_xmlGuiClient->actionCollection();
480 entryActions.insert( actionCollection->action(QLatin1String(KStandardAction::name(KStandardAction::Find))) );
481 entryActions.insert( actionCollection->action(QLatin1String(KStandardAction::name(KStandardAction::Print))) );
482 entryActions.insert( actionCollection->action(QLatin1String(
"rename_entry")) );
483 entryActions.insert( actionCollection->action(QLatin1String(
"change_color")) );
484 entryActions.insert( actionCollection->action(QLatin1String(
"save_to")) );
485 entryActions.insert( actionCollection->action(QLatin1String(
"copy_link_address")) );
488 pageActions.insert( actionCollection->action(QLatin1String(KStandardAction::name(KStandardAction::Cut))) );
489 pageActions.insert( actionCollection->action(QLatin1String(KStandardAction::name(KStandardAction::Paste))) );
490 pageActions.insert( actionCollection->action(QLatin1String(KStandardAction::name(KStandardAction::Replace))) );
491 pageActions.insert( actionCollection->action(QLatin1String(
"del_page")) );
492 pageActions.insert( actionCollection->action(QLatin1String(
"insert_date")) );
493 pageActions.insert( actionCollection->action(QLatin1String(
"auto_bullet")) );
494 pageActions.insert( actionCollection->action(QLatin1String(
"auto_decimal")) );
495 pageActions.insert( actionCollection->action(QLatin1String(
"manage_link")) );
496 pageActions.insert( actionCollection->action(QLatin1String(
"insert_checkmark")) );
499 bookActions.insert( actionCollection->action(QLatin1String(
"save_to_book")) );
500 bookActions.insert( actionCollection->action(QLatin1String(
"del_folder")) );
501 bookActions.insert( actionCollection->action(QLatin1String(
"sort_children_alpha")) );
502 bookActions.insert( actionCollection->action(QLatin1String(
"sort_children_by_date")) );
505 multiselectionActions.insert( actionCollection->action(QLatin1String(KStandardAction::name(KStandardAction::Find))) );
506 multiselectionActions.insert( actionCollection->action(QLatin1String(KStandardAction::name(KStandardAction::Print))));
507 multiselectionActions.insert( actionCollection->action(QLatin1String(
"del_mult")) );
508 multiselectionActions.insert( actionCollection->action(QLatin1String(
"save_to")) );
509 multiselectionActions.insert( actionCollection->action(QLatin1String(
"change_color")) );
511 m_autosaveTimer =
new QTimer(
this);
512 updateConfiguration();
514 connect(m_autosaveTimer, SIGNAL(timeout()), editor, SLOT(savePage()));
515 connect(treeview->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), m_autosaveTimer, SLOT(start()) );
522 connect( treeview->itemDelegate(), SIGNAL(closeEditor(
QWidget*,QAbstractItemDelegate::EndEditHint)),
523 SLOT(bookshelfEditItemFinished(
QWidget*,QAbstractItemDelegate::EndEditHint)) );
525 connect( editor, SIGNAL(currentCharFormatChanged(QTextCharFormat)),
526 SLOT(currentCharFormatChanged(QTextCharFormat)) );
530 void KJotsWidget::bookshelfEditItemFinished(
QWidget *, QAbstractItemDelegate::EndEditHint )
536 void KJotsWidget::currentCharFormatChanged(
const QTextCharFormat & fmt)
538 QString selectedAnchor = fmt.anchorHref();
539 if (selectedAnchor != activeAnchor)
541 activeAnchor = selectedAnchor;
542 if (!selectedAnchor.isEmpty())
544 QTextCursor c(editor->textCursor());
545 editor->selectLinkText(&c);
546 QString selectedText = c.selectedText();
547 if (!selectedText.isEmpty())
560 KConfig config( migrator + QLatin1String(
"rc") );
561 KConfigGroup migrationCfg( &config,
"Migration" );
562 const bool enabled = migrationCfg.readEntry(
"Enabled",
true );
563 const bool completed = migrationCfg.readEntry(
"Completed",
false );
564 const int currentVersion = migrationCfg.readEntry(
"Version", 0 );
565 const int targetVersion = migrationCfg.readEntry(
"TargetVersion", 1 );
566 if ( enabled && !completed && currentVersion < targetVersion ) {
567 kDebug() <<
"Performing Akonadi migration. Good luck!";
569 QStringList args = QStringList() << QLatin1String(
"--interactive-on-change");
570 if ( !type.isEmpty() )
571 args << QLatin1String(
"--type") << type;
573 const QString path = KStandardDirs::findExe( migrator );
574 proc.setProgram( path, args );
576 bool result = proc.waitForStarted();
578 result = proc.waitForFinished();
580 if ( result && proc.exitCode() == 0 ) {
581 kDebug() <<
"Akonadi migration has been successful";
584 kError() <<
"Akonadi migration failed!";
585 kError() <<
"command was: " << proc.program();
586 kError() <<
"exit code: " << proc.exitCode();
587 kError() <<
"stdout: " << proc.readAllStandardOutput();
588 kError() <<
"stderr: " << proc.readAllStandardError();
590 migrationCfg.writeEntry(
"Version", targetVersion );
591 migrationCfg.writeEntry(
"Completed",
true );
597 if ( browser->isVisible() ) {
606 QModelIndexList selection = treeview->selectionModel()->selectedRows();
607 int selectionSize = selection.size();
609 if ( !selectionSize ) {
611 foreach ( QAction* action, multiselectionActions )
612 action->setEnabled(
false);
613 foreach ( QAction* action, entryActions )
614 action->setEnabled(
false);
615 foreach ( QAction* action, bookActions )
616 action->setEnabled(
false);
617 foreach ( QAction* action, pageActions )
618 action->setEnabled(
false);
619 editor->setActionsEnabled(
false );
620 }
else if ( selectionSize > 1 ) {
621 foreach ( QAction* action, entryActions )
622 action->setEnabled(
false);
623 foreach ( QAction* action, bookActions )
624 action->setEnabled(
false);
625 foreach ( QAction* action, pageActions )
626 action->setEnabled(
false);
627 foreach ( QAction* action, multiselectionActions )
628 action->setEnabled(
true);
630 editor->setActionsEnabled(
false );
633 foreach ( QAction* action, multiselectionActions )
634 action->setEnabled(
false);
635 foreach ( QAction* action, entryActions )
636 action->setEnabled(
true);
638 QModelIndex idx = selection.at( 0 );
640 Collection col = idx.data( KJotsModel::CollectionRole ).value<Collection>();
641 if ( col.isValid() ) {
642 foreach ( QAction* action, pageActions )
643 action->setEnabled(
false);
644 const bool colIsRootCollection = ( col.parentCollection() == Collection::root() );
645 foreach ( QAction* action, bookActions ) {
646 if (action->objectName() == QLatin1String(
"del_folder") && colIsRootCollection ) {
647 action->setEnabled(
false );
649 action->setEnabled(
true );
654 editor->setActionsEnabled(
false );
656 foreach ( QAction* action, pageActions ) {
657 if (action->objectName() == QLatin1String(name( KStandardAction::Cut )) ) {
658 action->setEnabled(
activeEditor()->textCursor().hasSelection() );
660 action->setEnabled(
true );
663 foreach ( QAction* action, bookActions )
664 action->setEnabled(
false );
665 editor->setActionsEnabled(
true );
670 void KJotsWidget::copy() {
674 void KJotsWidget::configure()
678 connect( dialog, SIGNAL(configCommitted()), SLOT(updateConfiguration()) );
682 void KJotsWidget::updateConfiguration()
687 m_autosaveTimer->start();
689 m_autosaveTimer->stop();
692 void KJotsWidget::copySelectionToTitle()
694 QString newTitle( editor->textCursor().selectedText() );
696 if ( !newTitle.isEmpty() ) {
698 QModelIndexList rows = treeview->selectionModel()->selectedRows();
700 if ( rows.size() != 1 )
703 QModelIndex idx = rows.at( 0 );
705 treeview->model()->setData( idx, newTitle );
711 QModelIndexList selectedRows = treeview->selectionModel()->selectedRows();
713 if ( KMessageBox::questionYesNo(
this,
714 i18n(
"Do you really want to delete all selected books and pages?" ),
715 i18n(
"Delete?"), KStandardGuiItem::del(), KStandardGuiItem::cancel(),
716 QString(), KMessageBox::Dangerous ) != KMessageBox::Yes )
719 foreach (
const QModelIndex &index, selectedRows ) {
721 qlonglong
id = index.data( EntityTreeModel::ItemIdRole ).toLongLong(&ok);
725 new ItemDeleteJob( Item(
id ),
this );
728 id = index.data( EntityTreeModel::CollectionIdRole ).toLongLong(&ok);
731 new CollectionDeleteJob( Collection(
id ),
this );
738 QModelIndexList selectedRows = treeview->selectionModel()->selectedRows();
740 if ( selectedRows.size() != 1 )
743 const QModelIndex idx = selectedRows.at( 0 );
744 Item item = idx.data( EntityTreeModel::ItemRole ).value<Item>();
746 if ( !item.isValid() )
751 KMessageBox::information(topLevelWidget(),
752 i18n(
"This page is locked. You can only delete it when you first unlock it."),
753 i18n(
"Item is locked"));
757 if ( KMessageBox::warningContinueCancel(topLevelWidget(),
758 i18nc(
"remove the page, by title",
"<qt>Are you sure you want to delete the page <strong>%1</strong>?</qt>", idx.data().toString()),
759 i18n(
"Delete"), KStandardGuiItem::del(), KStandardGuiItem::cancel(), QLatin1String(
"DeletePageWarning")) == KMessageBox::Cancel) {
763 (void)
new Akonadi::ItemDeleteJob( item,
this );
768 QModelIndexList selectedRows = treeview->selectionModel()->selectedRows();
770 if ( selectedRows.size() != 1 )
773 const QModelIndex idx = selectedRows.at( 0 );
774 Collection col = idx.data( EntityTreeModel::CollectionRole ).value<Collection>();
776 if ( !col.isValid() )
779 if ( col.parentCollection() == Collection::root() )
784 KMessageBox::information(topLevelWidget(),
785 i18n(
"This book is locked. You can only delete it when you first unlock it."),
786 i18n(
"Item is locked"));
789 if ( KMessageBox::warningContinueCancel(topLevelWidget(),
790 i18nc(
"remove the book, by title",
"<qt>Are you sure you want to delete the book <strong>%1</strong>?</qt>", idx.data().toString()),
791 i18n(
"Delete"), KStandardGuiItem::del(), KStandardGuiItem::cancel(), QLatin1String(
"DeleteBookWarning")) == KMessageBox::Cancel) {
795 (void)
new Akonadi::CollectionDeleteJob( col,
this );
800 QModelIndexList selectedRows = treeview->selectionModel()->selectedRows();
802 if ( selectedRows.size() != 1 )
805 Collection col = selectedRows.at( 0 ).data( EntityTreeModel::CollectionRole ).value<Collection>();
807 if ( !col.isValid() )
810 Collection newCollection;
811 newCollection.setParentCollection( col );
813 QString title = i18nc(
"The default name for new books.",
"New Book" );
814 newCollection.setName( KRandom::randomString( 10 ) );
815 newCollection.setContentMimeTypes( QStringList() << Akonadi::Collection::mimeType() << Akonotes::Note::mimeType() );
817 Akonadi::EntityDisplayAttribute *eda =
new Akonadi::EntityDisplayAttribute();
818 eda->setIconName( QLatin1String(
"x-office-address-book") );
819 eda->setDisplayName( title );
820 newCollection.addAttribute( eda );
822 Akonadi::CollectionCreateJob *job =
new Akonadi::CollectionCreateJob( newCollection );
823 connect( job, SIGNAL(result(KJob*)),
this, SLOT(newBookResult(KJob*)) );
828 QModelIndexList selectedRows = treeview->selectionModel()->selectedRows();
830 if ( selectedRows.size() != 1 )
833 Item item = selectedRows.at( 0 ).data( EntityTreeModel::ItemRole ).value<Item>();
836 if ( item.isValid() )
838 col = selectedRows.at( 0 ).data( EntityTreeModel::ParentCollectionRole ).value<Collection>();
840 col = selectedRows.at( 0 ).data( EntityTreeModel::CollectionRole ).value<Collection>();
843 if ( !col.isValid() )
850 Akonotes::NoteCreatorAndSelector *creatorAndSelector =
new Akonotes::NoteCreatorAndSelector(treeview->selectionModel());
851 creatorAndSelector->createNote(collection);
854 void KJotsWidget::newPageResult( KJob* job )
857 kDebug() << job->errorString();
860 void KJotsWidget::newBookResult( KJob* job )
862 if ( job->error() ) {
863 kDebug() << job->errorString();
866 Akonadi::CollectionCreateJob *createJob = qobject_cast<Akonadi::CollectionCreateJob*>(job);
869 const Collection collection = createJob->collection();
870 if ( !collection.isValid() )
878 QHash<QString, QVariant> hash;
880 QList<QVariant> objectList;
882 const int rows = selProxy->rowCount();
883 const int column = 0;
884 for (
int row = 0; row < rows; ++row )
886 QModelIndex idx = selProxy->index( row, column, QModelIndex() );
891 objectList << QVariant::fromValue(static_cast<QObject *>(kjotsEntity));
894 hash.insert( QLatin1String(
"entities" ), objectList);
895 hash.insert( QLatin1String(
"i18n_TABLE_OF_CONTENTS" ),
896 i18nc(
"Header for 'Table of contents' section of rendered output",
"Table of contents") );
899 Template t = m_templateEngine->loadByName( QLatin1String(
"template.html" ) );
901 QString result = t->render(&c);
909 QHash<QString, QVariant> hash;
911 QList<QVariant> objectList;
913 const int rows = selProxy->rowCount();
914 const int column = 0;
915 for (
int row = 0; row < rows; ++row )
917 QModelIndex idx = selProxy->index( row, column, QModelIndex() );
922 objectList << QVariant::fromValue(static_cast<QObject *>(kjotsEntity));
925 hash.insert( QLatin1String(
"entities" ), objectList);
926 hash.insert( QLatin1String(
"i18n_TABLE_OF_CONTENTS" ),
927 i18nc(
"Header for 'Table of contents' section of rendered output",
"Table of contents") );
930 Template t = m_templateEngine->loadByName( QLatin1String(
"template.txt" ) );
932 QString result = t->render(&c);
941 QHash<QString, QVariant> hash;
943 QList<QVariant> objectList;
945 const int rows = selProxy->rowCount();
946 const int column = 0;
947 for (
int row = 0; row < rows; ++row )
949 QModelIndex idx = selProxy->index( row, column, QModelIndex() );
954 objectList << QVariant::fromValue(static_cast<QObject *>(kjotsEntity));
957 hash.insert( QLatin1String(
"entities" ), objectList);
960 QString currentTheme = m_loader->themeName();
961 m_loader->setTheme( QLatin1String(
"xml_output") );
962 Template t = m_templateEngine->loadByName( QLatin1String(
"template.xml" ) );
964 QString result = t->render(&c);
966 m_loader->setTheme(currentTheme);
972 const int rows = selProxy->rowCount();
977 QModelIndex idx = selProxy->index( 0, 0, QModelIndex());
983 editor->setDocument( document );
984 QTextCursor textCursor = document->property(
"textCursor" ).value<QTextCursor>();
985 if ( !textCursor.isNull() )
986 editor->setTextCursor( textCursor );
987 stackedWidget->setCurrentWidget( editor );
996 QTextCursor cursor(&doc);
999 stackedWidget->setCurrentWidget( browser );
1007 QString text = QInputDialog::getText(
this, i18n(
"Change Theme"),
1008 tr(
"Theme name:"), QLineEdit::Normal,
1009 m_loader->themeName(), &ok);
1010 if (!ok || text.isEmpty())
1012 return QLatin1String(
"default");
1030 QString currentTheme = m_loader->themeName();
1032 if (themeName.isEmpty())
1034 themeName = QLatin1String(
"default" );
1036 m_loader->setTheme(themeName);
1038 QString filename = KFileDialog::getSaveFileName();
1039 if (!filename.isEmpty())
1041 QFile exportFile ( filename );
1042 if ( !exportFile.open(QIODevice::WriteOnly | QIODevice::Text) ) {
1043 m_loader->setTheme(currentTheme);
1044 KMessageBox::error(0, i18n(
"<qt>Error opening internal file.</qt>"));
1051 m_loader->setTheme(currentTheme);
1056 QString currentTheme = m_loader->themeName();
1058 m_loader->setTheme( QLatin1String(
"plain_text") );
1060 QString filename = KFileDialog::getSaveFileName();
1061 if (!filename.isEmpty())
1063 QFile exportFile ( filename );
1064 if ( !exportFile.open(QIODevice::WriteOnly | QIODevice::Text) ) {
1065 m_loader->setTheme(currentTheme);
1066 KMessageBox::error(0, i18n(
"<qt>Error opening internal file.</qt>"));
1073 m_loader->setTheme(currentTheme);
1078 QString currentTheme = m_loader->themeName();
1080 m_loader->setTheme( QLatin1String(
"xml_output") );
1082 QString filename = KFileDialog::getSaveFileName();
1083 if (!filename.isEmpty())
1085 QFile exportFile ( filename );
1086 if ( !exportFile.open(QIODevice::WriteOnly | QIODevice::Text) ) {
1087 m_loader->setTheme(currentTheme);
1088 KMessageBox::error(0, i18n(
"<qt>Error opening internal file.</qt>"));
1095 m_loader->setTheme(currentTheme);
1100 QPrinter printer(QPrinter::HighResolution);
1101 printer.setDocName(QLatin1String(
"KJots_Print"));
1102 printer.setFullPage(
false);
1103 printer.setCreator(QLatin1String(
"KJots"));
1104 KPrintPreview previewdlg( &printer, 0 );
1112 QPrinter printer(QPrinter::HighResolution);
1113 printer.setDocName(QLatin1String(
"KJots_Print"));
1114 printer.setFullPage(
false);
1115 printer.setCreator(QLatin1String(
"KJots"));
1124 QPointer<QPrintDialog> printDialog =
new QPrintDialog(&printer,
this);
1126 QAbstractPrintDialog::PrintDialogOptions options = printDialog->enabledOptions();
1127 options &= ~QAbstractPrintDialog::PrintPageRange;
1129 options |= QAbstractPrintDialog::PrintSelection;
1130 printDialog->setEnabledOptions(options);
1132 printDialog->setWindowTitle(i18n(
"Send To Printer"));
1133 if (printDialog->exec() == QDialog::Accepted) {
1139 void KJotsWidget::print(QPrinter &printer)
1141 QTextDocument printDocument;
1142 if ( printer.printRange() == QPrinter::Selection )
1144 printDocument.setHtml(
activeEditor()->textCursor().selection().toHtml() );
1147 QString currentTheme = m_loader->themeName();
1148 m_loader->setTheme( QLatin1String(
"default") );
1150 m_loader->setTheme( currentTheme );
1153 QPainter p(&printer);
1157 QTextDocument *doc = &printDocument;
1159 QRectF body = QRectF(QPointF(0, 0), doc->pageSize());
1160 QPointF pageNumberPos;
1162 QAbstractTextDocumentLayout *layout = doc->documentLayout();
1163 layout->setPaintDevice(p.device());
1165 const int dpiy = p.device()->logicalDpiY();
1167 const int margin = (int) ((2/2.54)*dpiy);
1168 QTextFrameFormat fmt = doc->rootFrame()->frameFormat();
1169 fmt.setMargin(margin);
1170 doc->rootFrame()->setFrameFormat(fmt);
1172 body = QRectF(0, 0, p.device()->width(), p.device()->height());
1173 pageNumberPos = QPointF(body.width() - margin,
1174 body.height() - margin
1175 + QFontMetrics(doc->defaultFont(), p.device()).ascent()
1176 + 5 * p.device()->logicalDpiY() / 72);
1178 doc->setPageSize(body.size());
1180 int docCopies = printer.numCopies();
1181 for (
int copy = 0; copy < docCopies; ++copy) {
1183 int lastPage = layout->pageCount();
1184 for (
int page = 1; page <= lastPage ; ++page ) {
1186 p.translate(body.left(), body.top() - (page - 1) * body.height());
1187 QRectF view(0, (page - 1) * body.height(), body.width(), body.height());
1189 QAbstractTextDocumentLayout *layout = doc->documentLayout();
1190 QAbstractTextDocumentLayout::PaintContext ctx;
1192 p.setClipRect(view);
1198 ctx.palette.setColor(QPalette::Text, Qt::black);
1200 layout->draw(&p, ctx);
1202 if (!pageNumberPos.isNull()) {
1203 p.setClipping(
false);
1204 p.setFont(QFont(doc->defaultFont()));
1205 const QString pageString = QString::number(page);
1207 p.drawText(qRound(pageNumberPos.x() - p.fontMetrics().width(pageString)),
1208 qRound(pageNumberPos.y() + view.top()),
1214 if ( (page+1) <= lastPage ) {
1225 QModelIndexList list = treeview->selectionModel()->selectedRows();
1226 Q_ASSERT( list.size() == 1 );
1228 QModelIndex idx = list.at( 0 );
1230 const int column = idx.column();
1232 QModelIndex sibling = idx.sibling( idx.row() + step, column );
1233 while ( sibling.isValid() )
1235 if ( sibling.data( role ).toInt() >= 0 )
1237 treeview->selectionModel()->select( sibling, QItemSelectionModel::SelectCurrent );
1240 sibling = sibling.sibling( sibling.row() + step, column );
1242 kWarning() <<
"No valid selection";
1247 return selectNext( EntityTreeModel::CollectionIdRole, 1 );
1252 return selectNext( EntityTreeModel::ItemIdRole, 1 );
1257 return selectNext( EntityTreeModel::CollectionIdRole, -1 );
1262 return selectNext( EntityTreeModel::ItemIdRole, -1 );
1265 bool KJotsWidget::canGo(
int role,
int step )
const
1267 QModelIndexList list = treeview->selectionModel()->selectedRows();
1268 if ( list.size() != 1 )
1273 QModelIndex currentIdx = list.at( 0 );
1275 const int column = currentIdx.column();
1277 Q_ASSERT( currentIdx.isValid() );
1279 QModelIndex sibling = currentIdx.sibling( currentIdx.row() + step, column );
1281 while ( sibling.isValid() && sibling != currentIdx )
1283 if ( sibling.data( role ).toInt() >= 0 )
1286 sibling = sibling.sibling( sibling.row() + step, column );
1294 return canGo( EntityTreeModel::ItemIdRole, 1 );
1299 return canGo( EntityTreeModel::ItemIdRole, -1 );
1304 return canGo( EntityTreeModel::CollectionIdRole, 1 );
1309 return canGo( EntityTreeModel::CollectionIdRole, -1 );
1312 void KJotsWidget::selectionChanged(
const QItemSelection &selected,
const QItemSelection &deselected )
1314 Q_UNUSED( selected );
1321 if ( deselected.size() == 1 )
1323 editor->document()->setProperty(
"textCursor", QVariant::fromValue( editor->textCursor() ) );
1324 if ( editor->document()->isModified() )
1326 treeview->model()->setData( deselected.indexes().first(), QVariant::fromValue( editor->document() ),
KJotsModel::DocumentRole );
1334 void KJotsWidget::onShowSearch()
1340 if ( browserOrEditor->textCursor().hasSelection() ) {
1341 searchDialog->setHasSelection(
true);
1342 long dialogOptions = searchDialog->options();
1343 dialogOptions |= KFind::SelectedText;
1344 searchDialog->setOptions(dialogOptions);
1346 searchDialog->setHasSelection(
false);
1349 searchDialog->setFindHistory(searchHistory);
1350 searchDialog->show();
1358 void KJotsWidget::onUpdateSearch()
1360 if ( searchDialog->isVisible() ) {
1361 long searchOptions = searchDialog->options();
1362 if ( searchOptions & KFind::SelectedText ) {
1363 searchAllPages->setCheckState( Qt::Unchecked );
1364 searchAllPages->setEnabled(
false );
1366 searchAllPages->setEnabled(
true );
1369 if ( searchAllPages->checkState() == Qt::Checked ) {
1370 searchOptions &= ~KFind::SelectedText;
1371 searchDialog->setOptions( searchOptions );
1372 searchDialog->setHasSelection(
false );
1375 searchDialog->setHasSelection(
true );
1380 if ( searchAllPages->checkState() == Qt::Unchecked ) {
1381 searchDialog->setHasSelection(
true );
1384 searchOptions &= ~KFind::SelectedText;
1385 searchDialog->setOptions( searchOptions );
1386 searchDialog->setHasSelection(
false );
1394 void KJotsWidget::onStartSearch()
1396 QString searchPattern = searchDialog->pattern();
1397 if ( !searchHistory.contains ( searchPattern ) ) {
1398 searchHistory.prepend( searchPattern );
1402 QTextCursor cursor = browserOrEditor->textCursor();
1404 long searchOptions = searchDialog->options();
1405 if ( searchOptions & KFind::FromCursor ) {
1406 searchPos = cursor.position();
1408 cursor.movePosition( QTextCursor::End );
1409 searchEndPos = cursor.position();
1411 if ( searchOptions & KFind::SelectedText ) {
1412 searchBeginPos = cursor.selectionStart();
1413 searchEndPos = cursor.selectionEnd();
1416 cursor.movePosition( QTextCursor::End );
1417 searchEndPos = cursor.position();
1420 if ( searchOptions & KFind::FindBackwards ) {
1421 searchPos = searchEndPos;
1423 searchPos = searchBeginPos;
1427 m_xmlGuiClient->actionCollection()->action( QLatin1String(KStandardAction::name( KStandardAction::FindNext )) )->setEnabled(
true );
1435 void KJotsWidget::onRepeatSearch()
1437 if (
search(
false ) == 0 ) {
1438 KMessageBox::sorry( 0, i18n(
"<qt>No matches found.</qt>" ) );
1439 m_xmlGuiClient->actionCollection()->action( QLatin1String(KStandardAction::name( KStandardAction::FindNext )) )->setEnabled(
false );
1446 void KJotsWidget::onEndSearch()
1448 m_xmlGuiClient->actionCollection()->action( QLatin1String(KStandardAction::name( KStandardAction::FindNext )) )->setEnabled(
false );
1454 void KJotsWidget::onShowReplace()
1456 Q_ASSERT( editor->isVisible() );
1458 if ( editor->textCursor().hasSelection() ) {
1459 replaceDialog->setHasSelection(
true );
1460 long dialogOptions = replaceDialog->options();
1461 dialogOptions |= KFind::SelectedText;
1462 replaceDialog->setOptions( dialogOptions );
1464 replaceDialog->setHasSelection(
false );
1467 replaceDialog->setFindHistory( searchHistory );
1468 replaceDialog->setReplacementHistory( replaceHistory );
1469 replaceDialog->show();
1476 void KJotsWidget::onUpdateReplace()
1478 if ( replaceDialog->isVisible() ) {
1479 long replaceOptions = replaceDialog->options();
1480 if ( replaceOptions & KFind::SelectedText ) {
1481 replaceAllPages->setCheckState( Qt::Unchecked );
1482 replaceAllPages->setEnabled(
false );
1484 replaceAllPages->setEnabled(
true );
1487 if ( replaceAllPages->checkState() == Qt::Checked ) {
1488 replaceOptions &= ~KFind::SelectedText;
1489 replaceDialog->setOptions( replaceOptions );
1490 replaceDialog->setHasSelection(
false );
1493 replaceDialog->setHasSelection(
true );
1502 void KJotsWidget::onStartReplace()
1504 QString searchPattern = replaceDialog->pattern();
1505 if ( !searchHistory.contains ( searchPattern ) ) {
1506 searchHistory.prepend( searchPattern );
1509 QString replacePattern = replaceDialog->replacement();
1510 if ( !replaceHistory.contains ( replacePattern ) ) {
1511 replaceHistory.prepend( replacePattern );
1514 QTextCursor cursor = editor->textCursor();
1516 long replaceOptions = replaceDialog->options();
1517 if ( replaceOptions & KFind::FromCursor ) {
1518 replacePos = cursor.position();
1519 replaceBeginPos = 0;
1520 cursor.movePosition( QTextCursor::End );
1521 replaceEndPos = cursor.position();
1523 if ( replaceOptions & KFind::SelectedText ) {
1524 replaceBeginPos = cursor.selectionStart();
1525 replaceEndPos = cursor.selectionEnd();
1527 replaceBeginPos = 0;
1528 cursor.movePosition( QTextCursor::End );
1529 replaceEndPos = cursor.position();
1532 if ( replaceOptions & KFind::FindBackwards ) {
1533 replacePos = replaceEndPos;
1535 replacePos = replaceBeginPos;
1539 replaceStartPage = treeview->selectionModel()->selectedRows().first();
1542 QTimer::singleShot( 0,
this, SLOT(onRepeatReplace()) );
1548 void KJotsWidget::onRepeatReplace()
1552 QString searchPattern = replaceDialog->pattern();
1553 QString replacePattern = replaceDialog->replacement();
1557 long replaceOptions = replaceDialog->options();
1558 if ( replaceOptions & KReplaceDialog::PromptOnReplace ) {
1567 QTextCursor cursor = editor->textCursor();
1568 if ( !cursor.hasSelection() ) {
1574 QString replacementText = replacePattern;
1575 if ( replaceOptions & KReplaceDialog::BackReference ) {
1576 QRegExp regExp ( searchPattern, ( replaceOptions & Qt::CaseSensitive ) ?
1577 Qt::CaseSensitive : Qt::CaseInsensitive, QRegExp::RegExp2 );
1578 regExp.indexIn(cursor.selectedText());
1579 int capCount = regExp.numCaptures();
1580 for (
int i=0; i <= capCount; ++i ) {
1581 QString c = QString::fromLatin1(
"\\%1" ).arg( i );
1582 replacementText.replace( c, regExp.cap( i ) );
1586 if ( replaceOptions & KReplaceDialog::PromptOnReplace ) {
1587 dlg->
setLabel( cursor.selectedText(), replacementText );
1589 if ( !dlg->exec() ) {
1593 if ( dlg->
answer() != KDialog::User2 ) {
1594 cursor.insertText( replacementText );
1595 editor->setTextCursor( cursor );
1599 if ( dlg->
answer() == KDialog::User1 ) {
1600 replaceOptions |= ~KReplaceDialog::PromptOnReplace;
1603 cursor.insertText( replacementText );
1604 editor->setTextCursor( cursor );
1609 if ( replaced == found )
1611 KMessageBox::information( 0, i18np(
"<qt>Replaced 1 occurrence.</qt>",
"<qt>Replaced %1 occurrences.</qt>", replaced ) );
1613 else if ( replaced < found )
1615 KMessageBox::information( 0,
1616 i18np(
"<qt>Replaced %2 of 1 occurrence.</qt>",
"<qt>Replaced %2 of %1 occurrences.</qt>", found, replaced ) );
1627 void KJotsWidget::onEndReplace()
1638 int *beginPos = replacing ? &replaceBeginPos : &searchBeginPos;
1639 int *endPos = replacing ? &replaceEndPos : &searchEndPos;
1640 long options = replacing ? replaceDialog->options() : searchDialog->options();
1641 QString pattern = replacing ? replaceDialog->pattern() : searchDialog->pattern();
1642 int *curPos = replacing ? &replacePos : &searchPos;
1644 QModelIndex startPage = replacing ? replaceStartPage : treeview->selectionModel()->selectedRows().first();
1646 bool allPages =
false;
1647 QCheckBox *box = replacing ? replaceAllPages : searchAllPages;
1648 if ( box->isEnabled() && box->checkState() == Qt::Checked ) {
1652 QTextDocument::FindFlags findFlags = 0;
1653 if ( options & Qt::CaseSensitive ) {
1654 findFlags |= QTextDocument::FindCaseSensitively;
1657 if ( options & KFind::WholeWordsOnly ) {
1658 findFlags |= QTextDocument::FindWholeWords;
1661 if ( options & KFind::FindBackwards ) {
1662 findFlags |= QTextDocument::FindBackward;
1671 QTextDocument *theDoc = browserOrEditor->document();
1674 if ( options & KFind::RegularExpression ) {
1675 QRegExp regExp ( pattern, ( options & Qt::CaseSensitive ) ?
1676 Qt::CaseSensitive : Qt::CaseInsensitive, QRegExp::RegExp2 );
1677 cursor = theDoc->find( regExp, *curPos, findFlags );
1679 cursor = theDoc->find( pattern, *curPos, findFlags );
1682 if ( cursor.hasSelection() ) {
1683 if ( cursor.selectionStart() >= *beginPos && cursor.selectionEnd() <= *endPos ) {
1684 browserOrEditor->setTextCursor( cursor );
1685 browserOrEditor->ensureCursorVisible();
1686 *curPos = ( options & KFind::FindBackwards ) ?
1687 cursor.selectionStart() : cursor.selectionEnd();
1695 if ( replacing && !( options & KFind::FromCursor ) && !allPages ) {
1699 if ( ( options & KFind::FromCursor ) && !allPages ) {
1700 if ( KMessageBox::questionYesNo(
this,
1701 i18n(
"<qt>End of search area reached. Do you want to wrap around and continue?</qt>")) ==
1709 if ( options & KFind::FindBackwards ) {
1717 if ( startPage == treeview->selectionModel()->selectedRows().first() ) {
1723 cursor = editor->textCursor();
1724 cursor.movePosition( QTextCursor::End );
1725 *endPos = cursor.position();
1726 *curPos = ( options & KFind::FindBackwards ) ? *endPos : *beginPos;
1733 if ( attempts <= 1 ) {
1734 *curPos = ( options & KFind::FindBackwards ) ? *endPos : *beginPos;
1751 void KJotsWidget::dataChanged(
const QModelIndex &topLeft,
const QModelIndex &bottomRight )
1753 QModelIndexList rows = treeview->selectionModel()->selectedRows();
1755 if ( rows.size() != 1 )
1758 QItemSelection changed( topLeft, bottomRight );
1759 if ( changed.contains( rows.first() ) )
1770 m_orderProxy->saveOrder();
1775 void KJotsWidget::actionLock()
1777 QModelIndexList selection = treeview->selectionModel()->selectedRows();
1779 if ( selection.isEmpty() )
1782 Collection::List collections;
1784 foreach (
const QModelIndex &idx, selection )
1786 Collection col = idx.data( EntityTreeModel::CollectionRole ).value<Collection>();
1787 if ( col.isValid() )
1791 Item item = idx.data( EntityTreeModel::ItemRole ).value<Item>();
1792 if ( item.isValid() )
1796 if ( collections.isEmpty() && items.isEmpty() )
1802 void KJotsWidget::actionUnlock()
1804 QModelIndexList selection = treeview->selectionModel()->selectedRows();
1806 if ( selection.isEmpty() )
1809 Collection::List collections;
1811 foreach (
const QModelIndex &idx, selection )
1813 Collection col = idx.data( EntityTreeModel::CollectionRole ).value<Collection>();
1814 if ( col.isValid() )
1818 Item item = idx.data( EntityTreeModel::ItemRole ).value<Item>();
1819 if ( item.isValid() )
1823 if ( collections.isEmpty() && items.isEmpty() )
1829 void KJotsWidget::actionSortChildrenAlpha()
1831 QModelIndexList selection = treeview->selectionModel()->selectedRows();
1833 foreach(
const QModelIndex &index, selection )
1835 const QPersistentModelIndex persistent( index );
1837 m_orderProxy->clearOrder( persistent );
1841 void KJotsWidget::actionSortChildrenByDate()
1843 QModelIndexList selection = treeview->selectionModel()->selectedRows();
1845 foreach(
const QModelIndex &index, selection )
1847 const QPersistentModelIndex persistent( index );
1849 m_orderProxy->clearOrder( persistent );
1853 #include "kjotswidget.moc"
static int autoSaveInterval()
Get The interval in minutes at which books should be saved automatically.
Creates a notes resource, a book and a page if one does not already exist.
A wrapper QObject making some book and page properties available to Grantlee.
QString captionForSelection(const QString &sep) const
void setIndex(const QModelIndex &index)
static QList< int > splitterSizes()
Get How the main window is divided.
void setLabel(const QString &pattern, const QString &replacement)
void delayedInitialization(KActionCollection *)
void sortChildrenAlphabetically(const QModelIndex &parent)
void sortChildrenByCreationTime(const QModelIndex &parent)
static void setSplitterSizes(const QList< int > &v)
Set How the main window is divided.
void delayedInitialization()
static KJotsSettings * self()
static bool autoSave()
Get Whether books should be saved automatically.
void delayedInitialization()