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/Notes/NoteUtils>
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>
74 #include <KLocalizedString>
75 #include <KMessageBox>
76 #include <KReplaceDialog>
77 #include <kselectionproxymodel.h>
78 #include <KStandardDirs>
79 #include <KGlobalSettings>
80 #include <KXMLGUIClient>
82 #include <KPrintPreview>
85 #include <KMime/KMimeMessage>
95 #include "KJotsSettings.h"
101 #include "noteshared/attributes/notelockattribute.h"
106 #ifndef KDE_USE_FINAL
110 using namespace Akonadi;
111 using namespace Grantlee;
114 :
QWidget( parent, f ), m_xmlGuiClient( xmlGuiClient )
116 Akonadi::Control::widgetNeedsAkonadi(
this );
118 KConfigGroup migrationCfg( KGlobal::config(),
"General" );
119 const bool autoCreate = migrationCfg.readEntry(
"AutoCreateResourceOnStart",
true );
120 migrationCfg.writeEntry(
"AutoCreateResourceOnStart", autoCreate);
123 LocalResourceCreator *creator =
new LocalResourceCreator(
this );
124 creator->createIfMissing();
136 m_templateEngine =
new Engine(
this);
137 m_templateEngine->setPluginPaths( KStd.findDirs(
"lib",
QString() ) );
139 m_loader = FileSystemTemplateLoader::Ptr(
new FileSystemTemplateLoader() );
140 m_loader->setTemplateDirs( KStd.findDirs(
"data",
QLatin1String(
"kjots/themes" ) ) );
143 m_templateEngine->addTemplateLoader( m_loader );
147 ItemFetchScope scope;
148 scope.fetchFullPayload(
true );
149 scope.fetchAttribute< EntityDisplayAttribute >();
150 scope.fetchAttribute< NoteShared::NoteLockAttribute >();
152 ChangeRecorder *monitor =
new ChangeRecorder(
this );
153 monitor->fetchCollection(
true );
154 monitor->setItemFetchScope( scope );
155 monitor->setCollectionMonitored( Collection::root() );
156 monitor->setMimeTypeMonitored( Akonadi::NoteUtils::noteMimeType() );
158 m_kjotsModel =
new KJotsModel( monitor,
this );
163 m_orderProxy =
new EntityOrderProxyModel(
this );
164 m_orderProxy->setSourceModel( m_sortProxyModel );
166 KConfigGroup cfg( KGlobal::config(),
"KJotsEntityOrder" );
168 m_orderProxy->setOrderConfig( cfg );
170 treeview->setModel( m_orderProxy );
171 treeview->setSelectionMode( QAbstractItemView::ExtendedSelection );
172 treeview->setEditTriggers( QAbstractItemView::DoubleClicked );
176 selProxy =
new KSelectionProxyModel( treeview->selectionModel(), this );
177 selProxy->setSourceModel( treeview->model() );
187 KActionCollection *actionCollection = xmlGuiClient->actionCollection();
189 editor =
new KJotsEdit( treeview->selectionModel(), stackedWidget );
190 editor->createActions( actionCollection );
195 browser =
new KJotsBrowser( treeview->selectionModel(), stackedWidget );
202 action = actionCollection->addAction(
QLatin1String(
"go_next_book") );
203 action->setText( i18n(
"Next Book" ) );
205 action->setShortcut(
QKeySequence( Qt::CTRL + Qt::Key_D ) );
209 action = actionCollection->addAction(
QLatin1String(
"go_prev_book") );
210 action->setText( i18n(
"Previous Book" ) );
212 action->setShortcut(
QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_D ) );
216 action = actionCollection->addAction(
QLatin1String(
"go_next_page") );
217 action->setText( i18n(
"Next Page" ) );
219 action->setShortcut(
QKeySequence( Qt::CTRL + Qt::Key_PageDown ) );
223 action = actionCollection->addAction(
QLatin1String(
"go_prev_page") );
224 action->setText( i18n(
"Previous Page" ) );
226 action->setShortcut(
QKeySequence( Qt::CTRL + Qt::Key_PageUp ) );
230 action = actionCollection->addAction(
QLatin1String(
"new_page") );
231 action->setText( i18n(
"&New Page" ) );
232 action->setShortcut(
QKeySequence( Qt::CTRL + Qt::Key_N ) );
236 action = actionCollection->addAction(
QLatin1String(
"new_book"));
237 action->setText( i18n(
"New &Book..." ) );
238 action->setShortcut(
QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_N ) );
239 action->setIcon( KIcon(
QLatin1String(
"address-book-new") ) );
242 action = actionCollection->addAction(
QLatin1String(
"del_page") );
243 action->setText( i18n(
"&Delete Page" ) );
244 action->setShortcut(
QKeySequence( Qt::CTRL + Qt::Key_Delete ) );
245 action->setIcon( KIcon(
QLatin1String(
"edit-delete-page") ) );
248 action = actionCollection->addAction(
QLatin1String(
"del_folder") );
249 action->setText( i18n(
"Delete Boo&k" ) );
250 action->setShortcut(
QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_Delete ) );
254 action = actionCollection->addAction(
QLatin1String(
"del_mult") );
255 action->setText( i18n(
"Delete Selected" ) );
259 action = actionCollection->addAction(
QLatin1String(
"manual_save") );
260 action->setText( i18n(
"Manual Save" ) );
262 action->setShortcut(
QKeySequence( Qt::CTRL + Qt::Key_S ) );
264 action = actionCollection->addAction(
QLatin1String(
"auto_bullet") );
265 action->setText( i18n(
"Auto Bullets" ) );
266 action->setIcon( KIcon(
QLatin1String(
"format-list-unordered") ) );
267 action->setCheckable(
true );
269 action = actionCollection->addAction(
QLatin1String(
"auto_decimal") );
270 action->setText( i18n(
"Auto Decimal List" ) );
271 action->setIcon( KIcon(
QLatin1String(
"format-list-ordered") ) );
272 action->setCheckable(
true );
274 action = actionCollection->addAction(
QLatin1String(
"manage_link") );
275 action->setText( i18n(
"Link" ) );
278 action = actionCollection->addAction(
QLatin1String(
"insert_checkmark") );
279 action->setText( i18n(
"Insert Checkmark" ) );
281 action->setEnabled(
false );
283 action = actionCollection->addAction(
QLatin1String(
"rename_entry") );
284 action->setText( i18n(
"Rename..." ) );
286 action->setShortcut(
QKeySequence( Qt::CTRL + Qt::Key_M ) );
288 action = actionCollection->addAction(
QLatin1String(
"insert_date") );
289 action->setText( i18n(
"Insert Date" ) );
290 action->setShortcut(
QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_I ) );
291 action->setIcon( KIcon(
QLatin1String(
"view-calendar-time-spent") ) );
293 action = actionCollection->addAction(
QLatin1String(
"change_color") );
294 action->setIcon( KIcon(
QLatin1String(
"format-fill-color") ) );
295 action->setText( i18n(
"Change Color..." ) );
297 action = actionCollection->addAction(
QLatin1String(
"copy_link_address") );
298 action->setText( i18n(
"Copy Link Address" ) );
300 action = actionCollection->addAction(
QLatin1String(
"lock") );
301 action->setText(i18n(
"Lock Selected" ) );
303 connect( action, SIGNAL(triggered()), SLOT(actionLock()) );
305 action = actionCollection->addAction(
QLatin1String(
"unlock") );
306 action->setText( i18n(
"Unlock Selected" ) );
307 action->setIcon( KIcon(
QLatin1String(
"emblem-unlocked") ) );
308 connect( action, SIGNAL(triggered()), SLOT(actionUnlock()) );
310 action = actionCollection->addAction(
QLatin1String(
"sort_children_alpha") );
311 action->setText( i18n(
"Sort children alphabetically" ) );
312 connect( action, SIGNAL(triggered()), SLOT(actionSortChildrenAlpha()) );
314 action = actionCollection->addAction(
QLatin1String(
"sort_children_by_date") );
315 action->setText( i18n(
"Sort children by creation date" ) );
316 connect( action, SIGNAL(triggered()), SLOT(actionSortChildrenByDate()) );
318 action = KStandardAction::cut( editor, SLOT(cut()), actionCollection );
320 action->setEnabled(
false );
322 action = KStandardAction::copy(
this, SLOT(copy()), actionCollection );
325 action->setEnabled(
false );
327 KStandardAction::pasteText( editor, SLOT(paste()), actionCollection );
329 KStandardAction::undo( editor, SLOT(undo()), actionCollection );
330 KStandardAction::redo( editor, SLOT(redo()), actionCollection );
331 KStandardAction::selectAll( editor, SLOT(selectAll()), actionCollection );
333 action = actionCollection->addAction(
QLatin1String(
"copyIntoTitle") );
334 action->setText( i18n(
"Copy &into Page Title" ) );
335 action->setShortcut(
QKeySequence( Qt::CTRL + Qt::Key_T ) );
337 connect( action, SIGNAL(triggered()), SLOT(copySelectionToTitle()) );
339 action->setEnabled(
false );
341 action = actionCollection->addAction(
QLatin1String(
"paste_plain_text") );
342 action->setText( i18nc(
"@action Paste the text in the clipboard without rich text formatting.",
"Paste Plain Text" ) );
343 connect( action, SIGNAL(triggered()), editor, SLOT(pastePlainText()) );
345 KStandardAction::preferences(
this, SLOT(configure()), actionCollection );
347 bookmarkMenu = actionCollection->add<KActionMenu>(
QLatin1String(
"bookmarks") );
348 bookmarkMenu->setText( i18n(
"&Bookmarks" ) );
351 KBookmarkManager::managerForFile( KStandardDirs::locateLocal(
"data",
QLatin1String(
"kjots/bookmarks.xml") ),
QLatin1String(
"kjots") ),
352 bookmarks, bookmarkMenu->menu(), actionCollection );
356 KAction *bm_action = qobject_cast<KAction *>(actionCollection->action(
QLatin1String(
"add_bookmark")));
358 bm_action->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_B );
360 KStandardAction::find(
this, SLOT(onShowSearch()), actionCollection );
361 action = KStandardAction::findNext(
this, SLOT(onRepeatSearch()), actionCollection );
362 action->setEnabled(
false);
363 KStandardAction::replace(
this, SLOT(onShowReplace()), actionCollection );
365 action = actionCollection->addAction(
QLatin1String(
"save_to") );
366 action->setText( i18n(
"Rename..." ) );
368 action->setShortcut(
QKeySequence( Qt::CTRL + Qt::Key_M ) );
370 KActionMenu *exportMenu = actionCollection->add<KActionMenu>(
QLatin1String(
"save_to") );
371 exportMenu->setText( i18n(
"Export" ) );
372 exportMenu->setIcon( KIcon(
QLatin1String(
"document-export") ) );
374 action = actionCollection->addAction(
QLatin1String(
"save_to_ascii") );
375 action->setText( i18n(
"To Text File..." ) );
378 exportMenu->menu()->addAction( action );
380 action = actionCollection->addAction(
QLatin1String(
"save_to_html") );
381 action->setText( i18n(
"To HTML File..." ) );
384 exportMenu->menu()->addAction( action );
386 action = actionCollection->addAction(
QLatin1String(
"save_to_book") );
387 action->setText( i18n(
"To Book File..." ) );
388 action->setIcon( KIcon(
QLatin1String(
"x-office-address-book") ) );
390 exportMenu->menu()->addAction( action );
392 KStandardAction::print(
this, SLOT(
printSelection()), actionCollection);
395 if ( !KJotsSettings::splitterSizes().isEmpty() )
397 m_splitter->
setSizes( KJotsSettings::splitterSizes() );
405 connect( m_kjotsModel, SIGNAL(modelAboutToBeReset()), SLOT(saveState()));
406 connect( m_kjotsModel, SIGNAL(modelReset()), SLOT(restoreState()));
418 void KJotsWidget::restoreState()
420 ETMViewStateSaver *saver =
new ETMViewStateSaver;
421 saver->setView( treeview );
422 KConfigGroup cfg( KGlobal::config(),
"TreeState" );
423 saver->restoreState( cfg );
426 void KJotsWidget::saveState()
428 ETMViewStateSaver saver;
429 saver.setView( treeview );
430 KConfigGroup cfg( KGlobal::config(),
"TreeState" );
431 saver.saveState( cfg );
435 void KJotsWidget::delayedInitialization()
442 searchDialog =
new KFindDialog (
this, 0,
QStringList(),
false );
445 searchAllPages =
new QCheckBox(i18n(
"Search all pages"), searchDialog->findExtension());
448 connect(searchDialog, SIGNAL(okClicked()),
this, SLOT(onStartSearch()) );
449 connect(searchDialog, SIGNAL(cancelClicked()),
this, SLOT(onEndSearch()) );
451 connect(searchDialog, SIGNAL(optionsChanged()), SLOT(onUpdateSearch()) );
452 connect(searchAllPages, SIGNAL(stateChanged(
int)), SLOT(onUpdateSearch()) );
454 replaceDialog =
new KReplaceDialog (
this, 0, searchHistory, replaceHistory,
false );
457 replaceAllPages =
new QCheckBox(i18n(
"Search all pages"), replaceDialog->findExtension());
458 layout2->
addWidget(replaceAllPages, 0, 0);
460 connect(replaceDialog, SIGNAL(okClicked()),
this, SLOT(onStartReplace()) );
461 connect(replaceDialog, SIGNAL(cancelClicked()),
this, SLOT(onEndReplace()) );
462 connect(replaceDialog, SIGNAL(optionsChanged()), SLOT(onUpdateReplace()) );
463 connect(replaceAllPages, SIGNAL(stateChanged(
int)), SLOT(onUpdateReplace()) );
476 KActionCollection *actionCollection = m_xmlGuiClient->actionCollection();
479 entryActions.
insert( actionCollection->action(
QLatin1String(KStandardAction::name(KStandardAction::Find))) );
480 entryActions.
insert( actionCollection->action(
QLatin1String(KStandardAction::name(KStandardAction::Print))) );
487 pageActions.
insert( actionCollection->action(
QLatin1String(KStandardAction::name(KStandardAction::Cut))) );
488 pageActions.
insert( actionCollection->action(
QLatin1String(KStandardAction::name(KStandardAction::Paste))) );
489 pageActions.
insert( actionCollection->action(
QLatin1String(KStandardAction::name(KStandardAction::Replace))) );
504 multiselectionActions.
insert( actionCollection->action(
QLatin1String(KStandardAction::name(KStandardAction::Find))) );
505 multiselectionActions.
insert( actionCollection->action(
QLatin1String(KStandardAction::name(KStandardAction::Print))));
510 m_autosaveTimer =
new QTimer(
this);
511 updateConfiguration();
513 connect(m_autosaveTimer, SIGNAL(timeout()), editor, SLOT(savePage()));
521 connect( treeview->itemDelegate(), SIGNAL(closeEditor(
QWidget*,QAbstractItemDelegate::EndEditHint)),
522 SLOT(bookshelfEditItemFinished(
QWidget*,QAbstractItemDelegate::EndEditHint)) );
529 void KJotsWidget::bookshelfEditItemFinished(
QWidget *, QAbstractItemDelegate::EndEditHint )
535 void KJotsWidget::currentCharFormatChanged(
const QTextCharFormat & fmt)
538 if (selectedAnchor != activeAnchor)
540 activeAnchor = selectedAnchor;
544 editor->selectLinkText(&c);
545 QString selectedText = c.selectedText();
560 KConfigGroup migrationCfg( &config,
"Migration" );
561 const bool enabled = migrationCfg.readEntry(
"Enabled",
true );
562 const bool completed = migrationCfg.readEntry(
"Completed",
false );
563 const int currentVersion = migrationCfg.readEntry(
"Version", 0 );
564 const int targetVersion = migrationCfg.readEntry(
"TargetVersion", 1 );
565 if ( enabled && !completed && currentVersion < targetVersion ) {
566 kDebug() <<
"Performing Akonadi migration. Good luck!";
572 const QString path = KStandardDirs::findExe( migrator );
573 proc.setProgram( path, args );
575 bool result = proc.waitForStarted();
577 result = proc.waitForFinished();
579 if ( result && proc.exitCode() == 0 ) {
580 kDebug() <<
"Akonadi migration has been successful";
583 kError() <<
"Akonadi migration failed!";
584 kError() <<
"command was: " << proc.program();
585 kError() <<
"exit code: " << proc.exitCode();
586 kError() <<
"stdout: " << proc.readAllStandardOutput();
587 kError() <<
"stderr: " << proc.readAllStandardError();
589 migrationCfg.writeEntry(
"Version", targetVersion );
590 migrationCfg.writeEntry(
"Completed",
true );
605 QModelIndexList selection = treeview->selectionModel()->selectedRows();
606 int selectionSize = selection.size();
608 if ( !selectionSize ) {
610 foreach (
QAction* action, multiselectionActions )
612 foreach (
QAction* action, entryActions )
614 foreach (
QAction* action, bookActions )
616 foreach (
QAction* action, pageActions )
618 editor->setActionsEnabled(
false );
619 }
else if ( selectionSize > 1 ) {
620 foreach (
QAction* action, entryActions )
622 foreach (
QAction* action, bookActions )
624 foreach (
QAction* action, pageActions )
626 foreach (
QAction* action, multiselectionActions )
629 editor->setActionsEnabled(
false );
632 foreach (
QAction* action, multiselectionActions )
634 foreach (
QAction* action, entryActions )
639 Collection col = idx.
data( KJotsModel::CollectionRole ).
value<Collection>();
640 if ( col.isValid() ) {
641 foreach (
QAction* action, pageActions )
643 const bool colIsRootCollection = ( col.parentCollection() == Collection::root() );
644 foreach (
QAction* action, bookActions ) {
653 editor->setActionsEnabled(
false );
655 foreach (
QAction* action, pageActions ) {
662 foreach (
QAction* action, bookActions )
664 editor->setActionsEnabled(
true );
669 void KJotsWidget::copy() {
673 void KJotsWidget::configure()
677 connect( dialog, SIGNAL(configCommitted()), SLOT(updateConfiguration()) );
681 void KJotsWidget::updateConfiguration()
683 if (KJotsSettings::autoSave())
685 m_autosaveTimer->
setInterval(KJotsSettings::autoSaveInterval()*1000*60);
686 m_autosaveTimer->
start();
688 m_autosaveTimer->
stop();
691 void KJotsWidget::copySelectionToTitle()
693 QString newTitle( editor->textCursor().selectedText() );
695 if ( !newTitle.isEmpty() ) {
697 QModelIndexList rows = treeview->selectionModel()->selectedRows();
699 if ( rows.size() != 1 )
704 treeview->model()->setData( idx, newTitle );
710 QModelIndexList selectedRows = treeview->selectionModel()->selectedRows();
712 if ( KMessageBox::questionYesNo(
this,
713 i18n(
"Do you really want to delete all selected books and pages?" ),
714 i18n(
"Delete?"), KStandardGuiItem::del(), KStandardGuiItem::cancel(),
715 QString(), KMessageBox::Dangerous ) != KMessageBox::Yes )
718 foreach (
const QModelIndex &index, selectedRows ) {
720 qlonglong
id = index.
data( EntityTreeModel::ItemIdRole ).
toLongLong(&ok);
724 new ItemDeleteJob( Item(
id ),
this );
727 id = index.
data( EntityTreeModel::CollectionIdRole ).
toLongLong(&ok);
730 new CollectionDeleteJob( Collection(
id ),
this );
737 QModelIndexList selectedRows = treeview->selectionModel()->selectedRows();
739 if ( selectedRows.size() != 1 )
743 Item item = idx.
data( EntityTreeModel::ItemRole ).
value<Item>();
745 if ( !item.isValid() )
748 if( item.hasAttribute<NoteShared::NoteLockAttribute>() ) {
751 i18n(
"This page is locked. You can only delete it when you first unlock it."),
752 i18n(
"Item is locked"));
757 i18nc(
"remove the page, by title",
"<qt>Are you sure you want to delete the page <strong>%1</strong>?</qt>", idx.
data().
toString()),
758 i18n(
"Delete"), KStandardGuiItem::del(), KStandardGuiItem::cancel(),
QLatin1String(
"DeletePageWarning")) == KMessageBox::Cancel) {
762 (void)
new Akonadi::ItemDeleteJob( item,
this );
767 QModelIndexList selectedRows = treeview->selectionModel()->selectedRows();
769 if ( selectedRows.size() != 1 )
773 Collection col = idx.
data( EntityTreeModel::CollectionRole ).
value<Collection>();
775 if ( !col.isValid() )
778 if ( col.parentCollection() == Collection::root() )
781 if( col.hasAttribute<NoteShared::NoteLockAttribute>() ) {
784 i18n(
"This book is locked. You can only delete it when you first unlock it."),
785 i18n(
"Item is locked"));
789 i18nc(
"remove the book, by title",
"<qt>Are you sure you want to delete the book <strong>%1</strong>?</qt>", idx.
data().
toString()),
790 i18n(
"Delete"), KStandardGuiItem::del(), KStandardGuiItem::cancel(),
QLatin1String(
"DeleteBookWarning")) == KMessageBox::Cancel) {
794 (void)
new Akonadi::CollectionDeleteJob( col,
this );
799 QModelIndexList selectedRows = treeview->selectionModel()->selectedRows();
801 if ( selectedRows.size() != 1 )
804 Collection col = selectedRows.at( 0 ).data( EntityTreeModel::CollectionRole ).value<Collection>();
806 if ( !col.isValid() )
809 Collection newCollection;
810 newCollection.setParentCollection( col );
812 QString title = i18nc(
"The default name for new books.",
"New Book" );
813 newCollection.setName( KRandom::randomString( 10 ) );
814 newCollection.setContentMimeTypes(
QStringList() << Akonadi::Collection::mimeType() << Akonadi::NoteUtils::noteMimeType() );
816 Akonadi::EntityDisplayAttribute *eda =
new Akonadi::EntityDisplayAttribute();
818 eda->setDisplayName( title );
819 newCollection.addAttribute( eda );
821 Akonadi::CollectionCreateJob *job =
new Akonadi::CollectionCreateJob( newCollection );
822 connect( job, SIGNAL(result(KJob*)),
this, SLOT(newBookResult(KJob*)) );
827 QModelIndexList selectedRows = treeview->selectionModel()->selectedRows();
829 if ( selectedRows.size() != 1 )
832 Item item = selectedRows.at( 0 ).data( EntityTreeModel::ItemRole ).value<Item>();
835 if ( item.isValid() )
837 col = selectedRows.at( 0 ).data( EntityTreeModel::ParentCollectionRole ).value<Collection>();
839 col = selectedRows.at( 0 ).data( EntityTreeModel::CollectionRole ).value<Collection>();
842 if ( !col.isValid() )
849 Akonotes::NoteCreatorAndSelector *creatorAndSelector =
new Akonotes::NoteCreatorAndSelector(treeview->selectionModel());
850 creatorAndSelector->createNote(collection);
853 void KJotsWidget::newPageResult( KJob* job )
856 kDebug() << job->errorString();
859 void KJotsWidget::newBookResult( KJob* job )
861 if ( job->error() ) {
862 kDebug() << job->errorString();
865 Akonadi::CollectionCreateJob *createJob = qobject_cast<Akonadi::CollectionCreateJob*>(job);
868 const Collection collection = createJob->collection();
869 if ( !collection.isValid() )
881 const int rows = selProxy->rowCount();
882 const int column = 0;
883 for (
int row = 0; row < rows; ++row )
890 objectList << QVariant::fromValue(static_cast<QObject *>(kjotsEntity));
895 i18nc(
"Header for 'Table of contents' section of rendered output",
"Table of contents") );
898 Template t = m_templateEngine->loadByName(
QLatin1String(
"template.html" ) );
900 QString result = t->render(&c);
912 const int rows = selProxy->rowCount();
913 const int column = 0;
914 for (
int row = 0; row < rows; ++row )
921 objectList << QVariant::fromValue(static_cast<QObject *>(kjotsEntity));
926 i18nc(
"Header for 'Table of contents' section of rendered output",
"Table of contents") );
929 Template t = m_templateEngine->loadByName(
QLatin1String(
"template.txt" ) );
931 QString result = t->render(&c);
944 const int rows = selProxy->rowCount();
945 const int column = 0;
946 for (
int row = 0; row < rows; ++row )
953 objectList << QVariant::fromValue(static_cast<QObject *>(kjotsEntity));
959 QString currentTheme = m_loader->themeName();
961 Template t = m_templateEngine->loadByName(
QLatin1String(
"template.xml" ) );
963 QString result = t->render(&c);
965 m_loader->setTheme(currentTheme);
971 const int rows = selProxy->rowCount();
982 editor->setDocument( document );
984 if ( !textCursor.
isNull() )
985 editor->setTextCursor( textCursor );
1007 tr(
"Theme name:"), QLineEdit::Normal,
1008 m_loader->themeName(), &ok);
1029 QString currentTheme = m_loader->themeName();
1035 m_loader->setTheme(themeName);
1037 QString filename = KFileDialog::getSaveFileName();
1040 QFile exportFile ( filename );
1041 if ( !exportFile.
open(QIODevice::WriteOnly | QIODevice::Text) ) {
1042 m_loader->setTheme(currentTheme);
1043 KMessageBox::error(0, i18n(
"<qt>Error opening internal file.</qt>"));
1050 m_loader->setTheme(currentTheme);
1055 QString currentTheme = m_loader->themeName();
1059 QString filename = KFileDialog::getSaveFileName();
1062 QFile exportFile ( filename );
1063 if ( !exportFile.
open(QIODevice::WriteOnly | QIODevice::Text) ) {
1064 m_loader->setTheme(currentTheme);
1065 KMessageBox::error(0, i18n(
"<qt>Error opening internal file.</qt>"));
1072 m_loader->setTheme(currentTheme);
1077 QString currentTheme = m_loader->themeName();
1081 QString filename = KFileDialog::getSaveFileName();
1084 QFile exportFile ( filename );
1085 if ( !exportFile.
open(QIODevice::WriteOnly | QIODevice::Text) ) {
1086 m_loader->setTheme(currentTheme);
1087 KMessageBox::error(0, i18n(
"<qt>Error opening internal file.</qt>"));
1094 m_loader->setTheme(currentTheme);
1099 QPrinter printer(QPrinter::HighResolution);
1103 KPrintPreview previewdlg( &printer, 0 );
1111 QPrinter printer(QPrinter::HighResolution);
1128 options |= QAbstractPrintDialog::PrintSelection;
1129 printDialog->setEnabledOptions(options);
1131 printDialog->setWindowTitle(i18n(
"Send To Printer"));
1132 if (printDialog->exec() == QDialog::Accepted) {
1138 void KJotsWidget::print(
QPrinter &printer)
1141 if ( printer.
printRange() == QPrinter::Selection )
1146 QString currentTheme = m_loader->themeName();
1149 m_loader->setTheme( currentTheme );
1164 const int dpiy = p.device()->logicalDpiY();
1166 const int margin = (int) ((2/2.54)*dpiy);
1171 body =
QRectF(0, 0, p.device()->width(), p.device()->height());
1175 + 5 * p.device()->logicalDpiY() / 72);
1180 for (
int copy = 0; copy < docCopies; ++copy) {
1183 for (
int page = 1; page <= lastPage ; ++page ) {
1185 p.translate(body.
left(), body.
top() - (page - 1) * body.
height());
1191 p.setClipRect(view);
1197 ctx.palette.setColor(QPalette::Text, Qt::black);
1199 layout->draw(&p, ctx);
1201 if (!pageNumberPos.
isNull()) {
1202 p.setClipping(
false);
1206 p.drawText(qRound(pageNumberPos.
x() - p.fontMetrics().width(pageString)),
1207 qRound(pageNumberPos.
y() + view.top()),
1213 if ( (page+1) <= lastPage ) {
1224 QModelIndexList list = treeview->selectionModel()->selectedRows();
1225 Q_ASSERT( list.size() == 1 );
1229 const int column = idx.
column();
1234 if ( sibling.
data( role ).
toInt() >= 0 )
1236 treeview->selectionModel()->select( sibling, QItemSelectionModel::SelectCurrent );
1239 sibling = sibling.
sibling( sibling.
row() + step, column );
1241 kWarning() <<
"No valid selection";
1246 return selectNext( EntityTreeModel::CollectionIdRole, 1 );
1251 return selectNext( EntityTreeModel::ItemIdRole, 1 );
1256 return selectNext( EntityTreeModel::CollectionIdRole, -1 );
1261 return selectNext( EntityTreeModel::ItemIdRole, -1 );
1264 bool KJotsWidget::canGo(
int role,
int step )
const
1266 QModelIndexList list = treeview->selectionModel()->selectedRows();
1267 if ( list.size() != 1 )
1274 const int column = currentIdx.
column();
1276 Q_ASSERT( currentIdx.
isValid() );
1280 while ( sibling.isValid() && sibling != currentIdx )
1282 if ( sibling.data( role ).toInt() >= 0 )
1285 sibling = sibling.
sibling( sibling.row() + step, column );
1293 return canGo( EntityTreeModel::ItemIdRole, 1 );
1298 return canGo( EntityTreeModel::ItemIdRole, -1 );
1303 return canGo( EntityTreeModel::CollectionIdRole, 1 );
1308 return canGo( EntityTreeModel::CollectionIdRole, -1 );
1313 Q_UNUSED( selected );
1320 if ( deselected.
size() == 1 )
1322 editor->document()->setProperty(
"textCursor",
QVariant::fromValue( editor->textCursor() ) );
1323 if ( editor->document()->isModified() )
1333 void KJotsWidget::onShowSearch()
1340 searchDialog->setHasSelection(
true);
1341 long dialogOptions = searchDialog->options();
1342 dialogOptions |= KFind::SelectedText;
1343 searchDialog->setOptions(dialogOptions);
1345 searchDialog->setHasSelection(
false);
1348 searchDialog->setFindHistory(searchHistory);
1349 searchDialog->show();
1357 void KJotsWidget::onUpdateSearch()
1359 if ( searchDialog->isVisible() ) {
1360 long searchOptions = searchDialog->options();
1361 if ( searchOptions & KFind::SelectedText ) {
1368 if ( searchAllPages->
checkState() == Qt::Checked ) {
1369 searchOptions &= ~KFind::SelectedText;
1370 searchDialog->setOptions( searchOptions );
1371 searchDialog->setHasSelection(
false );
1374 searchDialog->setHasSelection(
true );
1379 if ( searchAllPages->
checkState() == Qt::Unchecked ) {
1380 searchDialog->setHasSelection(
true );
1383 searchOptions &= ~KFind::SelectedText;
1384 searchDialog->setOptions( searchOptions );
1385 searchDialog->setHasSelection(
false );
1393 void KJotsWidget::onStartSearch()
1395 QString searchPattern = searchDialog->pattern();
1396 if ( !searchHistory.
contains ( searchPattern ) ) {
1397 searchHistory.
prepend( searchPattern );
1403 long searchOptions = searchDialog->options();
1404 if ( searchOptions & KFind::FromCursor ) {
1410 if ( searchOptions & KFind::SelectedText ) {
1419 if ( searchOptions & KFind::FindBackwards ) {
1420 searchPos = searchEndPos;
1422 searchPos = searchBeginPos;
1426 m_xmlGuiClient->actionCollection()->action(
QLatin1String(KStandardAction::name( KStandardAction::FindNext )) )->setEnabled(
true );
1434 void KJotsWidget::onRepeatSearch()
1436 if (
search(
false ) == 0 ) {
1437 KMessageBox::sorry( 0, i18n(
"<qt>No matches found.</qt>" ) );
1438 m_xmlGuiClient->actionCollection()->action(
QLatin1String(KStandardAction::name( KStandardAction::FindNext )) )->setEnabled(
false );
1445 void KJotsWidget::onEndSearch()
1447 m_xmlGuiClient->actionCollection()->action(
QLatin1String(KStandardAction::name( KStandardAction::FindNext )) )->setEnabled(
false );
1453 void KJotsWidget::onShowReplace()
1455 Q_ASSERT( editor->isVisible() );
1457 if ( editor->textCursor().hasSelection() ) {
1458 replaceDialog->setHasSelection(
true );
1459 long dialogOptions = replaceDialog->options();
1460 dialogOptions |= KFind::SelectedText;
1461 replaceDialog->setOptions( dialogOptions );
1463 replaceDialog->setHasSelection(
false );
1466 replaceDialog->setFindHistory( searchHistory );
1467 replaceDialog->setReplacementHistory( replaceHistory );
1468 replaceDialog->show();
1475 void KJotsWidget::onUpdateReplace()
1477 if ( replaceDialog->isVisible() ) {
1478 long replaceOptions = replaceDialog->options();
1479 if ( replaceOptions & KFind::SelectedText ) {
1486 if ( replaceAllPages->
checkState() == Qt::Checked ) {
1487 replaceOptions &= ~KFind::SelectedText;
1488 replaceDialog->setOptions( replaceOptions );
1489 replaceDialog->setHasSelection(
false );
1492 replaceDialog->setHasSelection(
true );
1501 void KJotsWidget::onStartReplace()
1503 QString searchPattern = replaceDialog->pattern();
1504 if ( !searchHistory.
contains ( searchPattern ) ) {
1505 searchHistory.
prepend( searchPattern );
1508 QString replacePattern = replaceDialog->replacement();
1509 if ( !replaceHistory.
contains ( replacePattern ) ) {
1510 replaceHistory.
prepend( replacePattern );
1515 long replaceOptions = replaceDialog->options();
1516 if ( replaceOptions & KFind::FromCursor ) {
1518 replaceBeginPos = 0;
1522 if ( replaceOptions & KFind::SelectedText ) {
1526 replaceBeginPos = 0;
1531 if ( replaceOptions & KFind::FindBackwards ) {
1532 replacePos = replaceEndPos;
1534 replacePos = replaceBeginPos;
1538 replaceStartPage = treeview->selectionModel()->selectedRows().first();
1547 void KJotsWidget::onRepeatReplace()
1551 QString searchPattern = replaceDialog->pattern();
1552 QString replacePattern = replaceDialog->replacement();
1556 long replaceOptions = replaceDialog->options();
1557 if ( replaceOptions & KReplaceDialog::PromptOnReplace ) {
1573 QString replacementText = replacePattern;
1574 if ( replaceOptions & KReplaceDialog::BackReference ) {
1575 QRegExp regExp ( searchPattern, ( replaceOptions & Qt::CaseSensitive ) ?
1576 Qt::CaseSensitive : Qt::CaseInsensitive, QRegExp::RegExp2 );
1578 int capCount = regExp.numCaptures();
1579 for (
int i=0; i <= capCount; ++i ) {
1581 replacementText.
replace( c, regExp.cap( i ) );
1585 if ( replaceOptions & KReplaceDialog::PromptOnReplace ) {
1588 if ( !dlg->exec() ) {
1592 if ( dlg->
answer() != KDialog::User2 ) {
1594 editor->setTextCursor( cursor );
1598 if ( dlg->
answer() == KDialog::User1 ) {
1599 replaceOptions |= ~KReplaceDialog::PromptOnReplace;
1603 editor->setTextCursor( cursor );
1608 if ( replaced == found )
1610 KMessageBox::information( 0, i18np(
"<qt>Replaced 1 occurrence.</qt>",
"<qt>Replaced %1 occurrences.</qt>", replaced ) );
1612 else if ( replaced < found )
1614 KMessageBox::information( 0,
1615 i18np(
"<qt>Replaced %2 of 1 occurrence.</qt>",
"<qt>Replaced %2 of %1 occurrences.</qt>", found, replaced ) );
1626 void KJotsWidget::onEndReplace()
1637 int *beginPos = replacing ? &replaceBeginPos : &searchBeginPos;
1638 int *endPos = replacing ? &replaceEndPos : &searchEndPos;
1639 long options = replacing ? replaceDialog->options() : searchDialog->options();
1640 QString pattern = replacing ? replaceDialog->pattern() : searchDialog->pattern();
1641 int *curPos = replacing ? &replacePos : &searchPos;
1643 QModelIndex startPage = replacing ? replaceStartPage : treeview->selectionModel()->selectedRows().first();
1645 bool allPages =
false;
1646 QCheckBox *box = replacing ? replaceAllPages : searchAllPages;
1652 if ( options & Qt::CaseSensitive ) {
1653 findFlags |= QTextDocument::FindCaseSensitively;
1656 if ( options & KFind::WholeWordsOnly ) {
1657 findFlags |= QTextDocument::FindWholeWords;
1660 if ( options & KFind::FindBackwards ) {
1661 findFlags |= QTextDocument::FindBackward;
1673 if ( options & KFind::RegularExpression ) {
1674 QRegExp regExp ( pattern, ( options & Qt::CaseSensitive ) ?
1675 Qt::CaseSensitive : Qt::CaseInsensitive, QRegExp::RegExp2 );
1676 cursor = theDoc->
find( regExp, *curPos, findFlags );
1678 cursor = theDoc->
find( pattern, *curPos, findFlags );
1685 *curPos = ( options & KFind::FindBackwards ) ?
1694 if ( replacing && !( options & KFind::FromCursor ) && !allPages ) {
1698 if ( ( options & KFind::FromCursor ) && !allPages ) {
1699 if ( KMessageBox::questionYesNo(
this,
1700 i18n(
"<qt>End of search area reached. Do you want to wrap around and continue?</qt>")) ==
1708 if ( options & KFind::FindBackwards ) {
1716 if ( startPage == treeview->selectionModel()->selectedRows().first() ) {
1722 cursor = editor->textCursor();
1725 *curPos = ( options & KFind::FindBackwards ) ? *endPos : *beginPos;
1732 if ( attempts <= 1 ) {
1733 *curPos = ( options & KFind::FindBackwards ) ? *endPos : *beginPos;
1752 QModelIndexList rows = treeview->selectionModel()->selectedRows();
1754 if ( rows.size() != 1 )
1758 if ( changed.contains( rows.first() ) )
1766 KJotsSettings::setSplitterSizes(m_splitter->
sizes());
1768 KJotsSettings::self()->writeConfig();
1769 m_orderProxy->saveOrder();
1774 void KJotsWidget::actionLock()
1776 QModelIndexList selection = treeview->selectionModel()->selectedRows();
1778 if ( selection.isEmpty() )
1781 Collection::List collections;
1785 Collection col = idx.
data( EntityTreeModel::CollectionRole ).
value<Collection>();
1786 if ( col.isValid() )
1790 Item item = idx.
data( EntityTreeModel::ItemRole ).
value<Item>();
1791 if ( item.isValid() )
1795 if ( collections.isEmpty() && items.isEmpty() )
1801 void KJotsWidget::actionUnlock()
1803 QModelIndexList selection = treeview->selectionModel()->selectedRows();
1805 if ( selection.isEmpty() )
1808 Collection::List collections;
1812 Collection col = idx.
data( EntityTreeModel::CollectionRole ).
value<Collection>();
1813 if ( col.isValid() )
1817 Item item = idx.
data( EntityTreeModel::ItemRole ).
value<Item>();
1818 if ( item.isValid() )
1822 if ( collections.isEmpty() && items.isEmpty() )
1828 void KJotsWidget::actionSortChildrenAlpha()
1830 QModelIndexList selection = treeview->selectionModel()->selectedRows();
1836 m_orderProxy->clearOrder( persistent );
1840 void KJotsWidget::actionSortChildrenByDate()
1842 QModelIndexList selection = treeview->selectionModel()->selectedRows();
1848 m_orderProxy->clearOrder( persistent );
void setInterval(int msec)
QModelIndexList indexes() const
qlonglong toLongLong(bool *ok) const
iterator insert(const Key &key, const T &value)
void setSizes(const QList< int > &list)
void setStretchFactor(int index, int stretch)
virtual void setSourceModel(QAbstractItemModel *sourceModel)
QString anchorHref() const
void setFrameFormat(const QTextFrameFormat &format)
A wrapper QObject making some book and page properties available to Grantlee.
int selectionStart() const
void setHtml(const QString &text)
QString selectedText() const
bool registerObject(const QString &path, QObject *object, QFlags< QDBusConnection::RegisterOption > options)
bool contains(const QString &str, Qt::CaseSensitivity cs) const
QDBusConnection sessionBus()
const_iterator insert(const T &value)
typedef PrintDialogOptions
QString tr(const char *sourceText, const char *disambiguation, int n)
bool movePosition(MoveOperation operation, MoveMode mode, int n)
QString captionForSelection(const QString &sep) const
const char * name() const
QTextCursor find(const QString &subString, int position, QFlags< QTextDocument::FindFlag > options) const
bool hasSelection() const
QString number(int n, int base)
QList< int > sizes() const
QVariant property(const char *name) const
int toInt(bool *ok) const
void setCreator(const QString &creator)
QTextFrame * rootFrame() const
void insertText(const QString &text)
void setIndex(const QModelIndex &index)
QAbstractTextDocumentLayout * documentLayout() const
void setDocName(const QString &name)
void setLabel(const QString &pattern, const QString &replacement)
void setOpaqueResize(bool opaque)
PrintRange printRange() const
void setMargin(int margin)
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
void setTextCursor(const QTextCursor &cursor)
QString getText(QWidget *parent, const QString &title, const QString &label, QLineEdit::EchoMode mode, const QString &text, bool *ok, QFlags< Qt::WindowType > flags, QFlags< Qt::InputMethodHint > inputMethodHints)
QTextDocument * document() const
void setFullPage(bool fp)
QVariant fromValue(const T &value)
void delayedInitialization(KActionCollection *)
QString & replace(int position, int n, QChar after)
void ensureCursorVisible()
void sortChildrenAlphabetically(const QModelIndex &parent)
void sortChildrenByCreationTime(const QModelIndex &parent)
QVariant data(int role) const
QModelIndex sibling(int row, int column) const
void delayedInitialization()
virtual int pageCount() const =0
void setHtml(const QString &html)
qint64 write(const char *data, qint64 maxSize)
QString fromLatin1(const char *str, int size)
void prepend(const T &value)
void setPaintDevice(QPaintDevice *device)
QTextFrameFormat frameFormat() const
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Qt::CheckState checkState() const
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
void setMargin(qreal margin)
QTextCursor textCursor() const
void delayedInitialization()
void setCheckState(Qt::CheckState state)