~ubuntu-branches/ubuntu/vivid/qpdfview/vivid

« back to all changes in this revision

Viewing changes to sources/mainwindow.cpp

  • Committer: Package Import Robot
  • Author(s): Benjamin Eltzner
  • Date: 2013-01-02 14:12:52 UTC
  • mfrom: (1.2.5)
  • Revision ID: package-import@ubuntu.com-20130102141252-foi08cu5tkbu06p9
Tags: 0.3.7-1
* New upstream release.
* Fixed formatting of extended description in control file.
* New dependency libqt4-sql-sqlite.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 
3
3
Copyright 2012 Adam Reichold
 
4
Copyright 2012 Michał Trybus
 
5
Copyright 2012 Alexander Volkov
4
6
 
5
7
This file is part of qpdfview.
6
8
 
21
23
 
22
24
#include "mainwindow.h"
23
25
 
24
 
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
 
26
#include <QtXml>
 
27
 
 
28
#include "printoptionswidget.h"
 
29
#include "miscellaneous.h"
 
30
#include "settings.h"
 
31
#include "settingsdialog.h"
 
32
#include "recentlyusedmenu.h"
 
33
#include "bookmarkmenu.h"
 
34
 
 
35
MainWindow::MainWindow(const QString& instanceName, QWidget* parent) : QMainWindow(parent)
25
36
{
 
37
    setObjectName(instanceName);
 
38
 
26
39
    {
27
40
        // settings
28
41
 
29
 
        m_settings = new QSettings(this);
30
 
 
31
 
        if(m_settings->contains("mainWindow/iconTheme"))
32
 
        {
33
 
            QIcon::setThemeName(m_settings->value("mainWindow/iconTheme").toString());
34
 
        }
35
 
 
36
 
        if(m_settings->contains("mainWindow/styleSheet"))
37
 
        {
38
 
            qApp->setStyleSheet(m_settings->value("mainWindow/styleSheet").toString());
39
 
        }
40
 
 
41
 
        restoreSettings();
 
42
        m_settings = new Settings(this);
 
43
 
 
44
        m_settings->refresh();
 
45
 
 
46
        if(m_settings->mainWindow()->hasIconTheme())
 
47
        {
 
48
            QIcon::setThemeName(m_settings->mainWindow()->iconTheme());
 
49
        }
 
50
 
 
51
        if(m_settings->mainWindow()->hasStyleSheet())
 
52
        {
 
53
            qApp->setStyleSheet(m_settings->mainWindow()->styleSheet());
 
54
        }
42
55
    }
43
56
 
44
57
    setAcceptDrops(true);
49
62
    createDocks();
50
63
    createMenus();
51
64
 
52
 
    restoreGeometry(m_settings->value("mainWindow/geometry").toByteArray());
53
 
    restoreState(m_settings->value("mainWindow/state").toByteArray());
 
65
    restoreGeometry(m_settings->mainWindow()->geometry());
 
66
    restoreState(m_settings->mainWindow()->state());
 
67
 
 
68
    createDatabase();
54
69
 
55
70
    restoreTabs();
56
71
    restoreBookmarks();
82
97
{
83
98
    if(m_tabWidget->currentIndex() != -1)
84
99
    {
 
100
        savePerFileSettings(currentTab());
 
101
 
85
102
        if(currentTab()->open(filePath))
86
103
        {
 
104
            restorePerFileSettings(currentTab());
 
105
 
87
106
            QFileInfo fileInfo(filePath);
88
107
 
89
 
            m_settings->setValue("mainWindow/openPath", fileInfo.absolutePath());
 
108
            m_settings->mainWindow()->setOpenPath(fileInfo.absolutePath());
90
109
            m_recentlyUsedMenu->addOpenAction(filePath);
91
110
 
92
111
            m_tabWidget->setTabText(m_tabWidget->currentIndex(), fileInfo.completeBaseName());
113
132
 
114
133
bool MainWindow::openInNewTab(const QString& filePath, int page, const QRectF& highlight)
115
134
{
116
 
    DocumentView* newTab = new DocumentView();
 
135
    DocumentView* newTab = new DocumentView(this);
117
136
 
118
137
    if(newTab->open(filePath))
119
138
    {
120
 
        newTab->setContinousMode(m_settings->value("documentView/continuousMode", false).toBool());
121
 
        newTab->setLayoutMode(static_cast< DocumentView::LayoutMode >(m_settings->value("documentView/layoutMode", 0).toUInt()));
122
 
        newTab->setScaleMode(static_cast< DocumentView::ScaleMode >(m_settings->value("documentView/scaleMode", 0).toUInt()));
123
 
        newTab->setScaleFactor(m_settings->value("documentView/scaleFactor", 1.0).toReal());
124
 
        newTab->setRotation(static_cast< Poppler::Page::Rotation >(m_settings->value("documentView/rotation", 0).toUInt()));
125
 
        newTab->setHighlightAll(m_settings->value("documentView/highlightAll", false).toBool());
 
139
        newTab->setContinousMode(m_settings->documentView()->continuousMode());
 
140
        newTab->setLayoutMode(m_settings->documentView()->layoutMode());
 
141
        newTab->setScaleMode(m_settings->documentView()->scaleMode());
 
142
        newTab->setScaleFactor(m_settings->documentView()->scaleFactor());
 
143
        newTab->setRotation(m_settings->documentView()->rotation());
 
144
        newTab->setHighlightAll(m_settings->documentView()->highlightAll());
 
145
 
 
146
        restorePerFileSettings(newTab);
126
147
 
127
148
        QFileInfo fileInfo(filePath);
128
149
 
129
 
        m_settings->setValue("mainWindow/openPath", fileInfo.absolutePath());
 
150
        m_settings->mainWindow()->setOpenPath(fileInfo.absolutePath());
130
151
        m_recentlyUsedMenu->addOpenAction(filePath);
131
152
 
132
153
        int index = m_tabWidget->insertTab(m_tabWidget->currentIndex() + 1, newTab, fileInfo.completeBaseName());
216
237
    {
217
238
        m_refreshAction->setEnabled(true);
218
239
        m_saveCopyAction->setEnabled(true);
 
240
        m_saveAsAction->setEnabled(true);
219
241
        m_printAction->setEnabled(true);
220
242
 
221
243
        m_previousPageAction->setEnabled(true);
296
318
    {
297
319
        m_refreshAction->setEnabled(false);
298
320
        m_saveCopyAction->setEnabled(false);
 
321
        m_saveAsAction->setEnabled(false);
299
322
        m_printAction->setEnabled(false);
300
323
 
301
324
        m_previousPageAction->setEnabled(false);
382
405
 
383
406
void MainWindow::on_tabWidget_tabCloseRequested(int index)
384
407
{
 
408
    savePerFileSettings(tab(index));
 
409
 
385
410
    delete m_tabWidget->widget(index);
386
411
}
387
412
 
441
466
    {
442
467
        m_continuousModeAction->setChecked(continuousMode);
443
468
 
444
 
        m_settings->setValue("documentView/continuousMode", continuousMode);
 
469
        m_settings->documentView()->setContinuousMode(continuousMode);
445
470
    }
446
471
}
447
472
 
453
478
        m_twoPagesWithCoverPageModeAction->setChecked(layoutMode == DocumentView::TwoPagesWithCoverPageMode);
454
479
        m_multiplePagesModeAction->setChecked(layoutMode == DocumentView::MultiplePagesMode);
455
480
 
456
 
        m_settings->setValue("documentView/layoutMode", static_cast< uint >(layoutMode));
 
481
        m_settings->documentView()->setLayoutMode(layoutMode);
457
482
    }
458
483
}
459
484
 
490
515
            break;
491
516
        }
492
517
 
493
 
        m_settings->setValue("documentView/scaleMode", static_cast< uint >(scaleMode));
 
518
        m_settings->documentView()->setScaleMode(scaleMode);
494
519
    }
495
520
}
496
521
 
507
532
            m_zoomOutAction->setDisabled(qFuzzyCompare(scaleFactor, DocumentView::minimumScaleFactor()));
508
533
        }
509
534
 
510
 
        m_settings->setValue("documentView/scaleFactor", scaleFactor);
 
535
        m_settings->documentView()->setScaleFactor(scaleFactor);
511
536
    }
512
537
}
513
538
 
515
540
{
516
541
    if(senderIsCurrentTab())
517
542
    {
518
 
        m_settings->setValue("documentView/rotation", static_cast< uint >(rotation));
 
543
        m_settings->documentView()->setRotation(rotation);
519
544
    }
520
545
}
521
546
 
525
550
    {
526
551
        m_highlightAllCheckBox->setChecked(highlightAll);
527
552
 
528
 
        m_settings->setValue("documentView/highlightAll", highlightAll);
 
553
        m_settings->documentView()->setHighlightAll(highlightAll);
529
554
    }
530
555
}
531
556
 
630
655
{
631
656
    if(m_tabWidget->currentIndex() != -1)
632
657
    {
633
 
        QString path = m_settings->value("mainWindow/openPath", QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation)).toString();
634
 
        QString filePath = QFileDialog::getOpenFileName(this, tr("Open"), path, "Portable document format (*.pdf)");
 
658
        QString path = m_settings->mainWindow()->openPath();
 
659
        QString filePath = QFileDialog::getOpenFileName(this, tr("Open"), path, Settings::MainWindow::fileFilter());
635
660
 
636
661
        if(!filePath.isEmpty())
637
662
        {
646
671
 
647
672
void MainWindow::on_openInNewTab_triggered()
648
673
{
649
 
    QString path = m_settings->value("mainWindow/openPath", QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation)).toString();
650
 
    QStringList filePaths = QFileDialog::getOpenFileNames(this, tr("Open in new tab"), path, "Portable document format (*.pdf)");
 
674
    QString path = m_settings->mainWindow()->openPath();
 
675
    QStringList filePaths = QFileDialog::getOpenFileNames(this, tr("Open in new tab"), path, Settings::MainWindow::fileFilter());
651
676
 
652
677
    if(!filePaths.isEmpty())
653
678
    {
674
699
 
675
700
void MainWindow::on_saveCopy_triggered()
676
701
{
677
 
    QString path = m_settings->value("mainWindow/savePath", QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation)).toString();
678
 
    QString filePath = QFileDialog::getSaveFileName(this, tr("Save copy"), QFileInfo(QDir(path), QFileInfo(currentTab()->filePath()).fileName()).filePath(), "Portable document format (*.pdf)");
 
702
    QString path = m_settings->mainWindow()->savePath();
 
703
    QString filePath = QFileDialog::getSaveFileName(this, tr("Save copy"), QFileInfo(QDir(path), QFileInfo(currentTab()->filePath()).fileName()).filePath(), Settings::MainWindow::fileFilter());
679
704
 
680
705
    if(!filePath.isEmpty())
681
706
    {
682
 
        if(currentTab()->saveCopy(filePath))
 
707
        if(currentTab()->save(filePath, false))
683
708
        {
684
 
            m_settings->setValue("mainWindow/savePath", QFileInfo(filePath).absolutePath());
 
709
            m_settings->mainWindow()->setSavePath(QFileInfo(filePath).absolutePath());
685
710
        }
686
711
        else
687
712
        {
690
715
    }
691
716
}
692
717
 
 
718
void MainWindow::on_saveAs_triggered()
 
719
{
 
720
    QString path = m_settings->mainWindow()->savePath();
 
721
    QString filePath = QFileDialog::getSaveFileName(this, tr("Save as"), QFileInfo(QDir(path), QFileInfo(currentTab()->filePath()).fileName()).filePath(), Settings::MainWindow::fileFilter());
 
722
 
 
723
    if(!filePath.isEmpty())
 
724
    {
 
725
        if(currentTab()->save(filePath, true))
 
726
        {
 
727
            open(filePath, currentTab()->currentPage());
 
728
 
 
729
            m_settings->mainWindow()->setSavePath(QFileInfo(filePath).absolutePath());
 
730
        }
 
731
        else
 
732
        {
 
733
            QMessageBox::warning(this, tr("Warning"), tr("Could not save as '%1'.").arg(filePath));
 
734
        }
 
735
    }
 
736
}
 
737
 
693
738
void MainWindow::on_print_triggered()
694
739
{
695
740
    QPrinter* printer = new QPrinter();
783
828
    m_searchProgressLineEdit->setFocus();
784
829
}
785
830
 
 
831
void MainWindow::on_search_returnPressed(const Qt::KeyboardModifiers& modifiers)
 
832
{
 
833
    if(modifiers == Qt::ShiftModifier)
 
834
    {
 
835
        m_searchTimer->stop();
 
836
 
 
837
        if(!m_searchProgressLineEdit->text().isEmpty())
 
838
        {
 
839
            for(int index = 0; index < m_tabWidget->count(); ++index)
 
840
            {
 
841
                tab(index)->startSearch(m_searchProgressLineEdit->text(), m_matchCaseCheckBox->isChecked());
 
842
            }
 
843
        }
 
844
    }
 
845
    else
 
846
    {
 
847
        on_search_timeout();
 
848
    }
 
849
}
 
850
 
786
851
void MainWindow::on_search_timeout()
787
852
{
788
853
    m_searchTimer->stop();
852
917
 
853
918
    if(settingsDialog->exec() == QDialog::Accepted)
854
919
    {
855
 
        restoreSettings();
 
920
        m_settings->refresh();
856
921
 
857
 
        m_tabWidget->setTabPosition(static_cast< QTabWidget::TabPosition >(m_settings->value("mainWindow/tabPosition", 0).toUInt()));
858
 
        m_tabWidget->setTabBarPolicy(static_cast< TabWidget::TabBarPolicy >(m_settings->value("mainWindow/tabVisibility", 0).toUInt()));
 
922
        m_tabWidget->setTabPosition(m_settings->mainWindow()->tabPosition());
 
923
        m_tabWidget->setTabBarPolicy(m_settings->mainWindow()->tabVisibility());
859
924
 
860
925
        for(int index = 0; index < m_tabWidget->count(); ++index)
861
926
        {
932
997
    tableView->setAlternatingRowColors(true);
933
998
    tableView->setSortingEnabled(true);
934
999
    tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
 
1000
    tableView->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
 
1001
 
 
1002
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
 
1003
 
 
1004
    tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
 
1005
    tableView->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
 
1006
 
 
1007
#else
935
1008
 
936
1009
    tableView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
937
 
    tableView->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
938
1010
    tableView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
 
1011
 
 
1012
#endif // QT_VERSION
 
1013
 
939
1014
    tableView->verticalHeader()->setVisible(false);
940
1015
 
941
1016
    tableView->setModel(fontsModel);
948
1023
    dialog->layout()->addWidget(tableView);
949
1024
    dialog->layout()->addWidget(dialogButtonBox);
950
1025
 
951
 
    dialog->resize(m_settings->value("mainWindow/fontsDialogSize", dialog->sizeHint()).toSize());
 
1026
    dialog->resize(m_settings->mainWindow()->fontsDialogSize(dialog->sizeHint()));
952
1027
    dialog->exec();
953
 
    m_settings->setValue("mainWindow/fontsDialogSize", dialog->size());
 
1028
    m_settings->mainWindow()->setFontsDialogSize(dialog->size());
954
1029
 
955
1030
    delete fontsModel;
956
1031
    delete dialog;
976
1051
 
977
1052
void MainWindow::on_presentation_triggered()
978
1053
{
979
 
    bool sync = m_settings->value("presentationView/sync", false).toBool();
980
 
    int screen = m_settings->value("presentationView/screen", -1).toInt();
 
1054
    bool sync = m_settings->presentationView()->sync();
 
1055
    int screen = m_settings->presentationView()->screen();
981
1056
 
982
1057
    currentTab()->presentation(sync, screen);
983
1058
}
1008
1083
 
1009
1084
void MainWindow::on_closeTab_triggered()
1010
1085
{
 
1086
    savePerFileSettings(currentTab());
 
1087
 
1011
1088
    delete m_tabWidget->currentWidget();
1012
1089
}
1013
1090
 
1017
1094
 
1018
1095
    while(m_tabWidget->count() > 0)
1019
1096
    {
 
1097
        savePerFileSettings(tab(0));
 
1098
 
1020
1099
        delete m_tabWidget->widget(0);
1021
1100
    }
1022
1101
 
1036
1115
 
1037
1116
        while(m_tabWidget->count() > 0)
1038
1117
        {
 
1118
            savePerFileSettings(tab(0));
 
1119
 
1039
1120
            delete m_tabWidget->widget(0);
1040
1121
        }
1041
1122
 
1186
1267
    QDialog* dialog = new QDialog(this);
1187
1268
 
1188
1269
    QTextBrowser* textBrowser = new QTextBrowser(dialog);
1189
 
    textBrowser->setSearchPaths(QStringList() << DATA_INSTALL_PATH << QApplication::applicationDirPath());
 
1270
    textBrowser->setSearchPaths(QStringList() << DATA_INSTALL_PATH << QDir(QApplication::applicationDirPath()).filePath("data"));
1190
1271
    textBrowser->setSource(QUrl("help.html"));
1191
1272
 
1192
1273
    QDialogButtonBox* dialogButtonBox = new QDialogButtonBox(QDialogButtonBox::Ok, Qt::Horizontal, dialog);
1197
1278
    dialog->layout()->addWidget(textBrowser);
1198
1279
    dialog->layout()->addWidget(dialogButtonBox);
1199
1280
 
1200
 
    dialog->resize(m_settings->value("mainWindow/contentsDialogSize", dialog->sizeHint()).toSize());
 
1281
    dialog->resize(m_settings->mainWindow()->contentsDialogSize(dialog->sizeHint()));
1201
1282
    dialog->exec();
1202
 
    m_settings->setValue("mainWindow/contentsDialogSize", dialog->size());
 
1283
    m_settings->mainWindow()->setContentsDialogSize(dialog->size());
1203
1284
 
1204
1285
    delete dialog;
1205
1286
}
1245
1326
    }
1246
1327
}
1247
1328
 
1248
 
void MainWindow::closeEvent(QCloseEvent *event)
 
1329
void MainWindow::closeEvent(QCloseEvent* event)
1249
1330
{
1250
1331
    saveTabs();
1251
1332
    saveBookmarks();
1252
1333
 
 
1334
    for(int index = 0; index < m_tabWidget->count(); ++index)
 
1335
    {
 
1336
        savePerFileSettings(tab(index));
 
1337
    }
 
1338
 
1253
1339
    removeToolBar(m_searchToolBar);
1254
1340
 
1255
 
    if(m_settings->value("mainWindow/trackRecentlyUsed", false).toBool())
1256
 
    {
1257
 
        m_settings->setValue("mainWindow/recentlyUsed", m_recentlyUsedMenu->filePaths());
1258
 
    }
1259
 
    else
1260
 
    {
1261
 
        m_settings->remove("mainWindow/recentlyUsed");
1262
 
    }
 
1341
    m_settings->mainWindow()->setRecentlyUsed(m_settings->mainWindow()->trackRecentlyUsed() ? m_recentlyUsedMenu->filePaths() : QStringList());
1263
1342
 
1264
 
    m_settings->setValue("mainWindow/geometry", m_fullscreenAction->isChecked() ? m_fullscreenAction->data() : saveGeometry());
1265
 
    m_settings->setValue("mainWindow/state", saveState());
 
1343
    m_settings->mainWindow()->setGeometry(m_fullscreenAction->isChecked() ? m_fullscreenAction->data().toByteArray() : saveGeometry());
 
1344
    m_settings->mainWindow()->setState(saveState());
1266
1345
 
1267
1346
    QMainWindow::closeEvent(event);
1268
1347
}
1301
1380
    }
1302
1381
}
1303
1382
 
1304
 
void MainWindow::restoreSettings()
1305
 
{
1306
 
    PageItem::setCacheSize(m_settings->value("pageItem/cacheSize", 32 * 1024 * 1024).toInt());
1307
 
 
1308
 
    PageItem::setDecoratePages(m_settings->value("pageItem/decoratePages", true).toBool());
1309
 
    PageItem::setDecorateLinks(m_settings->value("pageItem/decorateLinks", true).toBool());
1310
 
    PageItem::setDecorateFormFields(m_settings->value("pageItem/decorateFormFields", true).toBool());
1311
 
 
1312
 
    PageItem::setInvertColors(m_settings->value("pageItem/invertColors", false).toBool());
1313
 
 
1314
 
    PageItem::setCopyModifiers(static_cast< Qt::KeyboardModifier >(m_settings->value("pageItem/copyModifiers", 0x02000000).toInt()));
1315
 
    PageItem::setAnnotateModifiers(static_cast< Qt::KeyboardModifier >(m_settings->value("pageItem/annotateModifiers", 0x04000000).toInt()));
1316
 
 
1317
 
    DocumentView::setOpenUrl(m_settings->value("documentView/openUrl", false).toBool());
1318
 
 
1319
 
    DocumentView::setAutoRefresh(m_settings->value("documentView/autoRefresh", false).toBool());
1320
 
 
1321
 
    DocumentView::setAntialiasing(m_settings->value("documentView/antialiasing", true).toBool());
1322
 
    DocumentView::setTextAntialiasing(m_settings->value("documentView/textAntialiasing", true).toBool());
1323
 
    DocumentView::setTextHinting(m_settings->value("documentView/textHinting", false).toBool());
1324
 
 
1325
 
    DocumentView::setOverprintPreview(m_settings->value("documentView/overprintPreview", false).toBool());
1326
 
 
1327
 
    DocumentView::setPrefetch(m_settings->value("documentView/prefetch", false).toBool());
1328
 
 
1329
 
    DocumentView::setPagesPerRow(m_settings->value("documentView/pagesPerRow", 3).toInt());
1330
 
 
1331
 
    DocumentView::setPageSpacing(m_settings->value("documentView/pageSpacing", 5.0).toReal());
1332
 
    DocumentView::setThumbnailSpacing(m_settings->value("documentView/thumbnailSpacing", 3.0).toReal());
1333
 
 
1334
 
    DocumentView::setThumbnailSize(m_settings->value("documentView/thumbnailSize", 150.0).toReal());
1335
 
 
1336
 
    DocumentView::setZoomModifiers(static_cast< Qt::KeyboardModifier >(m_settings->value("documentView/zoomModifiers", 0x04000000).toInt()));
1337
 
    DocumentView::setRotateModifiers(static_cast< Qt::KeyboardModifier >(m_settings->value("documentView/rotateModifiers", 0x02000000).toInt()));
1338
 
    DocumentView::setHorizontalModifiers(static_cast< Qt::KeyboardModifier >(m_settings->value("documentView/horizontalModifiers", 0x08000000).toInt()));
1339
 
 
1340
 
    DocumentView::setHighlightDuration(m_settings->value("documentView/highlightDuration", 5000).toInt());
1341
 
 
1342
 
    DocumentView::setSourceEditor(m_settings->value("documentView/sourceEditor").toString());
1343
 
}
1344
 
 
1345
1383
DocumentView* MainWindow::currentTab() const
1346
1384
{
1347
1385
    return qobject_cast< DocumentView* >(m_tabWidget->currentWidget());
1384
1422
    m_tabWidget->setTabsClosable(true);
1385
1423
    m_tabWidget->setElideMode(Qt::ElideRight);
1386
1424
 
1387
 
    m_tabWidget->setTabPosition(static_cast< QTabWidget::TabPosition >(m_settings->value("mainWindow/tabPosition", 0).toUInt()));
1388
 
    m_tabWidget->setTabBarPolicy(static_cast< TabWidget::TabBarPolicy >(m_settings->value("mainWindow/tabVisibility", 0).toUInt()));
 
1425
    m_tabWidget->setTabPosition(m_settings->mainWindow()->tabPosition());
 
1426
    m_tabWidget->setTabBarPolicy(m_settings->mainWindow()->tabVisibility());
1389
1427
 
1390
1428
    setCentralWidget(m_tabWidget);
1391
1429
 
1437
1475
    m_searchTimer->setSingleShot(true);
1438
1476
 
1439
1477
    connect(m_searchProgressLineEdit, SIGNAL(textEdited(QString)), m_searchTimer, SLOT(start()));
1440
 
    connect(m_searchProgressLineEdit, SIGNAL(returnPressed()), SLOT(on_search_timeout()));
 
1478
    connect(m_searchProgressLineEdit, SIGNAL(returnPressed(Qt::KeyboardModifiers)), SLOT(on_search_returnPressed(Qt::KeyboardModifiers)));
1441
1479
    connect(m_searchTimer, SIGNAL(timeout()), SLOT(on_search_timeout()));
1442
1480
 
1443
1481
    m_matchCaseCheckBox = new QCheckBox(tr("Match &case"), this);
1480
1518
    m_saveCopyAction->setIconVisibleInMenu(true);
1481
1519
    connect(m_saveCopyAction, SIGNAL(triggered()), SLOT(on_saveCopy_triggered()));
1482
1520
 
 
1521
    // save as
 
1522
 
 
1523
    m_saveAsAction = new QAction(tr("Save &as..."), this);
 
1524
    m_saveAsAction->setShortcut(QKeySequence::SaveAs);
 
1525
    m_saveAsAction->setIcon(QIcon::fromTheme("document-save-as", QIcon(":icons/document-save-as.svg")));
 
1526
    m_saveAsAction->setIconVisibleInMenu(true);
 
1527
    connect(m_saveAsAction, SIGNAL(triggered()), SLOT(on_saveAs_triggered()));
 
1528
 
1483
1529
    // print
1484
1530
 
1485
1531
    m_printAction = new QAction(tr("&Print..."), this);
1783
1829
    m_fileToolBar = addToolBar(tr("&File"));
1784
1830
    m_fileToolBar->setObjectName("fileToolBar");
1785
1831
 
1786
 
    foreach(QString action, m_settings->value("mainWindow/fileToolBar", QStringList() << "openInNewTab" << "refresh").toStringList())
 
1832
    foreach(QString action, m_settings->mainWindow()->fileToolBar())
1787
1833
    {
1788
1834
        if(action == "open") { m_fileToolBar->addAction(m_openAction); }
1789
1835
        else if(action == "openInNewTab") { m_fileToolBar->addAction(m_openInNewTabAction); }
1790
1836
        else if(action == "refresh") { m_fileToolBar->addAction(m_refreshAction); }
1791
1837
        else if(action == "saveCopy") { m_fileToolBar->addAction(m_saveCopyAction); }
 
1838
        else if(action == "saveAs") { m_fileToolBar->addAction(m_saveAsAction); }
1792
1839
        else if(action == "print") { m_fileToolBar->addAction(m_printAction); }
1793
1840
    }
1794
1841
 
1797
1844
    m_editToolBar = addToolBar(tr("&Edit"));
1798
1845
    m_editToolBar->setObjectName("editToolBar");
1799
1846
 
1800
 
    foreach(QString action, m_settings->value("mainWindow/editToolBar", QStringList() << "currentPage" << "previousPage" << "nextPage").toStringList())
 
1847
    foreach(QString action, m_settings->mainWindow()->editToolBar())
1801
1848
    {
1802
1849
        if(action == "currentPage") { m_currentPageSpinBox->setVisible(true); m_editToolBar->addWidget(m_currentPageSpinBox); }
1803
1850
        else if(action == "previousPage") { m_editToolBar->addAction(m_previousPageAction); }
1815
1862
    m_viewToolBar = addToolBar(tr("&View"));
1816
1863
    m_viewToolBar->setObjectName("viewToolBar");
1817
1864
 
1818
 
    foreach(QString action, m_settings->value("mainWindow/viewToolBar", QStringList() << "scaleFactor" << "zoomIn" << "zoomOut").toStringList())
 
1865
    foreach(QString action, m_settings->mainWindow()->viewToolBar())
1819
1866
    {
1820
1867
        if(action == "continuousMode") { m_viewToolBar->addAction(m_continuousModeAction); }
1821
1868
        else if(action == "twoPagesMode") { m_viewToolBar->addAction(m_twoPagesModeAction); }
1869
1916
    m_outlineView->setAlternatingRowColors(true);
1870
1917
    m_outlineView->setEditTriggers(QAbstractItemView::NoEditTriggers);
1871
1918
 
 
1919
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
 
1920
 
 
1921
    m_outlineView->header()->setSectionResizeMode(QHeaderView::Stretch);
 
1922
 
 
1923
#else
 
1924
 
 
1925
    m_outlineView->header()->setResizeMode(QHeaderView::Stretch);
 
1926
 
 
1927
#endif // QT_VERSION
 
1928
 
1872
1929
    m_outlineView->header()->setVisible(false);
1873
 
    m_outlineView->header()->setResizeMode(QHeaderView::Stretch);
1874
1930
 
1875
1931
    connect(m_outlineView, SIGNAL(clicked(QModelIndex)), SLOT(on_outline_clicked(QModelIndex)));
1876
1932
 
1892
1948
    m_propertiesView->setAlternatingRowColors(true);
1893
1949
    m_propertiesView->setEditTriggers(QAbstractItemView::NoEditTriggers);
1894
1950
 
 
1951
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
 
1952
 
 
1953
    m_propertiesView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
 
1954
    m_propertiesView->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
 
1955
 
 
1956
#else
 
1957
 
 
1958
    m_propertiesView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
 
1959
    m_propertiesView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
 
1960
 
 
1961
#endif // QT_VERSION
 
1962
 
1895
1963
    m_propertiesView->horizontalHeader()->setVisible(false);
1896
 
    m_propertiesView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
1897
1964
    m_propertiesView->verticalHeader()->setVisible(false);
1898
 
    m_propertiesView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
1899
1965
 
1900
1966
    m_propertiesDock->setWidget(m_propertiesView);
1901
1967
 
1928
1994
 
1929
1995
    m_recentlyUsedMenu = new RecentlyUsedMenu(this);
1930
1996
 
1931
 
    if(m_settings->value("mainWindow/trackRecentlyUsed", false).toBool())
 
1997
    if(m_settings->mainWindow()->trackRecentlyUsed())
1932
1998
    {
1933
 
        foreach(QString filePath, m_settings->value("mainWindow/recentlyUsed").toStringList())
 
1999
        foreach(QString filePath, m_settings->mainWindow()->recentlyUsed())
1934
2000
        {
1935
2001
            m_recentlyUsedMenu->addOpenAction(filePath);
1936
2002
        }
1954
2020
 
1955
2021
    m_fileMenu->addAction(m_refreshAction);
1956
2022
    m_fileMenu->addAction(m_saveCopyAction);
 
2023
    m_fileMenu->addAction(m_saveAsAction);
1957
2024
    m_fileMenu->addAction(m_printAction);
1958
2025
    m_fileMenu->addSeparator();
1959
2026
    m_fileMenu->addAction(m_exitAction);
2039
2106
    m_helpMenu->addAction(m_aboutAction);
2040
2107
}
2041
2108
 
 
2109
void MainWindow::createDatabase()
 
2110
{
 
2111
#ifdef WITH_SQL
 
2112
 
 
2113
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
 
2114
 
 
2115
    QString path = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
 
2116
 
 
2117
#else
 
2118
 
 
2119
    QString path = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
 
2120
 
 
2121
#endif // QT_VERSION
 
2122
 
 
2123
    QDir().mkpath(path);
 
2124
 
 
2125
    m_database = QSqlDatabase::addDatabase("QSQLITE");
 
2126
    m_database.setDatabaseName(QDir(path).filePath("database"));
 
2127
    m_database.open();
 
2128
 
 
2129
    if(m_database.isOpen())
 
2130
    {
 
2131
        m_database.transaction();
 
2132
 
 
2133
        QStringList tables = m_database.tables();
 
2134
        QSqlQuery query(m_database);
 
2135
 
 
2136
        // tabs
 
2137
 
 
2138
        if(!tables.contains("tabs_v2"))
 
2139
        {
 
2140
            query.exec("CREATE TABLE tabs_v2 "
 
2141
                       "(filePath TEXT"
 
2142
                       ",instanceName TEXT"
 
2143
                       ",currentPage INTEGER"
 
2144
                       ",continuousMode INTEGER"
 
2145
                       ",layoutMode INTEGER"
 
2146
                       ",scaleMode INTEGER"
 
2147
                       ",scaleFactor REAL"
 
2148
                       ",rotation INTEGER)");
 
2149
 
 
2150
            if(!query.isActive())
 
2151
            {
 
2152
                qDebug() << query.lastError();
 
2153
            }
 
2154
 
 
2155
            restoreTabsFromXml(true);
 
2156
        }
 
2157
 
 
2158
        // bookmarks
 
2159
 
 
2160
        if(!tables.contains("bookmarks_v1"))
 
2161
        {
 
2162
            query.exec("CREATE TABLE bookmarks_v1 "
 
2163
                       "(filePath TEXT"
 
2164
                       ",pages TEXT)");
 
2165
 
 
2166
            if(!query.isActive())
 
2167
            {
 
2168
                qDebug() << query.lastError();
 
2169
            }
 
2170
 
 
2171
            restoreBookmarksFromXml(true);
 
2172
        }
 
2173
 
 
2174
        // per-file settings
 
2175
 
 
2176
        if(!tables.contains("perfilesettings_v1"))
 
2177
        {
 
2178
            query.exec("CREATE TABLE perfilesettings_v1 "
 
2179
                       "(lastUsed INTEGER"
 
2180
                       ",filePath TEXT PRIMARY KEY"
 
2181
                       ",currentPage INTEGER"
 
2182
                       ",continuousMode INTEGER"
 
2183
                       ",layoutMode INTEGER"
 
2184
                       ",scaleMode INTEGER"
 
2185
                       ",scaleFactor REAL"
 
2186
                       ",rotation INTEGER)");
 
2187
 
 
2188
            if(!query.isActive())
 
2189
            {
 
2190
                qDebug() << query.lastError();
 
2191
            }
 
2192
        }
 
2193
 
 
2194
        if(m_settings->mainWindow()->restorePerFileSettings())
 
2195
        {
 
2196
            query.exec("DELETE FROM perfilesettings_v1 WHERE filePath IN (SELECT filePath FROM perfilesettings_v1 ORDER BY lastUsed DESC LIMIT -1 OFFSET 1000)");
 
2197
        }
 
2198
        else
 
2199
        {
 
2200
            query.exec("DELETE FROM perfilesettings_v1");
 
2201
        }
 
2202
 
 
2203
        if(!query.isActive())
 
2204
        {
 
2205
            qDebug() << query.lastError();
 
2206
        }
 
2207
 
 
2208
        m_database.commit();
 
2209
    }
 
2210
    else
 
2211
    {
 
2212
        qDebug() << m_database.lastError();
 
2213
    }
 
2214
 
 
2215
#endif // WITH_SQL
 
2216
}
 
2217
 
2042
2218
void MainWindow::restoreTabs()
2043
2219
{
2044
 
    if(m_settings->value("mainWindow/restoreTabs", false).toBool())
2045
 
    {
2046
 
        QFile file(QFileInfo(QDir(QFileInfo(m_settings->fileName()).path()), "tabs.xml").filePath());
 
2220
#ifdef WITH_SQL
 
2221
 
 
2222
    if(m_database.isOpen())
 
2223
    {
 
2224
        m_database.transaction();
 
2225
 
 
2226
        QSqlQuery query(m_database);
 
2227
        query.prepare("SELECT filePath,currentPage,continuousMode,layoutMode,scaleMode,scaleFactor,rotation FROM tabs_v2 WHERE instanceName==?");
 
2228
 
 
2229
        query.bindValue(0, objectName());
 
2230
 
 
2231
        query.exec();
 
2232
 
 
2233
        while(query.next())
 
2234
        {
 
2235
            if(!query.isActive())
 
2236
            {
 
2237
                qDebug() << query.lastError();
 
2238
                break;
 
2239
            }
 
2240
 
 
2241
            if(openInNewTab(query.value(0).toString()))
 
2242
            {
 
2243
                currentTab()->setContinousMode(static_cast< bool >(query.value(2).toUInt()));
 
2244
                currentTab()->setLayoutMode(static_cast< DocumentView::LayoutMode >(query.value(3).toUInt()));
 
2245
 
 
2246
                currentTab()->setScaleMode(static_cast< DocumentView::ScaleMode >(query.value(4).toUInt()));
 
2247
                currentTab()->setScaleFactor(query.value(5).toReal());
 
2248
 
 
2249
                currentTab()->setRotation(static_cast< Poppler::Page::Rotation >(query.value(6).toUInt()));
 
2250
 
 
2251
                currentTab()->jumpToPage(query.value(1).toInt());
 
2252
            }
 
2253
        }
 
2254
 
 
2255
        m_database.commit();
 
2256
    }
 
2257
 
 
2258
#else
 
2259
 
 
2260
    restoreTabsFromXml(false);
 
2261
 
 
2262
#endif // WITH_SQL
 
2263
}
 
2264
 
 
2265
void MainWindow::restoreTabsFromXml(bool removeFile)
 
2266
{
 
2267
    if(m_settings->mainWindow()->restoreTabs())
 
2268
    {
 
2269
        QFile file(QDir(QFileInfo(m_settings->fileName()).path()).filePath("tabs.xml"));
2047
2270
 
2048
2271
        if(file.open(QIODevice::ReadOnly | QIODevice::Text))
2049
2272
        {
2080
2303
            }
2081
2304
 
2082
2305
            file.close();
 
2306
 
 
2307
            if(removeFile)
 
2308
            {
 
2309
                file.remove();
 
2310
            }
2083
2311
        }
2084
2312
    }
2085
2313
}
2086
2314
 
2087
2315
void MainWindow::saveTabs()
2088
2316
{
2089
 
    QFile file(QFileInfo(QDir(QFileInfo(m_settings->fileName()).path()), "tabs.xml").filePath());
2090
 
 
2091
 
    if(m_settings->value("mainWindow/restoreTabs", false).toBool())
 
2317
#ifdef WITH_SQL
 
2318
 
 
2319
    if(m_database.isOpen())
 
2320
    {
 
2321
        m_database.transaction();
 
2322
 
 
2323
        QSqlQuery query(m_database);
 
2324
 
 
2325
        if(m_settings->mainWindow()->restoreTabs())
 
2326
        {
 
2327
            query.prepare("DELETE FROM tabs_v2 WHERE instanceName==?");
 
2328
 
 
2329
            query.bindValue(0, objectName());
 
2330
 
 
2331
            query.exec();
 
2332
 
 
2333
            if(!query.isActive())
 
2334
            {
 
2335
                qDebug() << query.lastError();
 
2336
            }
 
2337
 
 
2338
            query.prepare("INSERT INTO tabs_v2 "
 
2339
                          "(filePath,instanceName,currentPage,continuousMode,layoutMode,scaleMode,scaleFactor,rotation)"
 
2340
                          " VALUES (?,?,?,?,?,?,?,?)");
 
2341
 
 
2342
            for(int index = 0; index < m_tabWidget->count(); ++index)
 
2343
            {
 
2344
                query.bindValue(0, QFileInfo(tab(index)->filePath()).absoluteFilePath());
 
2345
                query.bindValue(1, objectName());
 
2346
                query.bindValue(2, tab(index)->currentPage());
 
2347
 
 
2348
                query.bindValue(3, static_cast< uint >(tab(index)->continousMode()));
 
2349
                query.bindValue(4, static_cast< uint >(tab(index)->layoutMode()));
 
2350
 
 
2351
                query.bindValue(5, static_cast< uint >(tab(index)->scaleMode()));
 
2352
                query.bindValue(6, tab(index)->scaleFactor());
 
2353
 
 
2354
                query.bindValue(7, static_cast< uint >(tab(index)->rotation()));
 
2355
 
 
2356
                query.exec();
 
2357
 
 
2358
                if(!query.isActive())
 
2359
                {
 
2360
                    qDebug() << query.lastError();
 
2361
                    break;
 
2362
                }
 
2363
            }
 
2364
        }
 
2365
        else
 
2366
        {
 
2367
            query.exec("DELETE FROM tabs_v2");
 
2368
 
 
2369
            if(!query.isActive())
 
2370
            {
 
2371
                qDebug() << query.lastError();
 
2372
            }
 
2373
        }
 
2374
 
 
2375
        m_database.commit();
 
2376
    }
 
2377
 
 
2378
#else
 
2379
 
 
2380
    QFile file(QDir(QFileInfo(m_settings->fileName()).path()).filePath("tabs.xml"));
 
2381
 
 
2382
    if(m_settings->mainWindow()->restoreTabs())
2092
2383
    {
2093
2384
        if(file.open(QIODevice::WriteOnly | QIODevice::Text))
2094
2385
        {
2126
2417
    {
2127
2418
        file.remove();
2128
2419
    }
 
2420
 
 
2421
#endif // WITH_SQL
2129
2422
}
2130
2423
 
2131
2424
void MainWindow::restoreBookmarks()
2132
2425
{
2133
 
    if(m_settings->value("mainWindow/restoreBookmarks", false).toBool())
2134
 
    {
2135
 
        QFile file(QFileInfo(QDir(QFileInfo(m_settings->fileName()).path()), "bookmarks.xml").filePath());
 
2426
#ifdef WITH_SQL
 
2427
 
 
2428
    if(m_database.isOpen())
 
2429
    {
 
2430
        m_database.transaction();
 
2431
 
 
2432
        QSqlQuery query(m_database);
 
2433
        query.exec("SELECT filePath,pages FROM bookmarks_v1");
 
2434
 
 
2435
        while(query.next())
 
2436
        {
 
2437
            if(!query.isActive())
 
2438
            {
 
2439
                qDebug() << query.lastError();
 
2440
                break;
 
2441
            }
 
2442
 
 
2443
            BookmarkMenu* bookmark = new BookmarkMenu(query.value(0).toString(), this);
 
2444
 
 
2445
            QStringList pages = query.value(1).toString().split(",", QString::SkipEmptyParts);
 
2446
 
 
2447
            foreach(QString page, pages)
 
2448
            {
 
2449
                bookmark->addJumpToPageAction(page.toInt());
 
2450
            }
 
2451
 
 
2452
            connect(bookmark, SIGNAL(openTriggered(QString)), SLOT(on_bookmark_openTriggered(QString)));
 
2453
            connect(bookmark, SIGNAL(openInNewTabTriggered(QString)), SLOT(on_bookmark_openInNewTabTriggered(QString)));
 
2454
            connect(bookmark, SIGNAL(jumpToPageTriggered(QString,int)), SLOT(on_bookmark_jumpToPageTriggered(QString,int)));
 
2455
 
 
2456
            m_bookmarksMenu->addMenu(bookmark);
 
2457
        }
 
2458
 
 
2459
        m_database.commit();
 
2460
    }
 
2461
 
 
2462
#else
 
2463
 
 
2464
    restoreBookmarksFromXml(false);
 
2465
 
 
2466
#endif // WITH_SQL
 
2467
}
 
2468
 
 
2469
void MainWindow::restoreBookmarksFromXml(bool removeFile)
 
2470
{
 
2471
    if(m_settings->mainWindow()->restoreBookmarks())
 
2472
    {
 
2473
        QFile file(QDir(QFileInfo(m_settings->fileName()).path()).filePath("bookmarks.xml"));
2136
2474
 
2137
2475
        if(file.open(QIODevice::ReadOnly | QIODevice::Text))
2138
2476
        {
2167
2505
            }
2168
2506
 
2169
2507
            file.close();
 
2508
 
 
2509
            if(removeFile)
 
2510
            {
 
2511
                file.remove();
 
2512
            }
2170
2513
        }
2171
2514
    }
2172
2515
}
2173
2516
 
2174
2517
void MainWindow::saveBookmarks()
2175
2518
{
2176
 
    QFile file(QFileInfo(QDir(QFileInfo(m_settings->fileName()).path()), "bookmarks.xml").filePath());
2177
 
 
2178
 
    if(m_settings->value("mainWindow/restoreBookmarks", false).toBool())
 
2519
#ifdef WITH_SQL
 
2520
 
 
2521
    if(m_database.isOpen())
 
2522
    {
 
2523
        m_database.transaction();
 
2524
 
 
2525
        QSqlQuery query(m_database);
 
2526
        query.exec("DELETE FROM bookmarks_v1");
 
2527
 
 
2528
        if(!query.isActive())
 
2529
        {
 
2530
            qDebug() << query.lastError();
 
2531
        }
 
2532
 
 
2533
        if(m_settings->mainWindow()->restoreBookmarks())
 
2534
        {
 
2535
            query.prepare("INSERT INTO bookmarks_v1 "
 
2536
                          "(filePath,pages)"
 
2537
                          " VALUES (?,?)");
 
2538
 
 
2539
            foreach(QAction* action, m_bookmarksMenu->actions())
 
2540
            {
 
2541
                BookmarkMenu* bookmark = qobject_cast< BookmarkMenu* >(action->menu());
 
2542
 
 
2543
                if(bookmark != 0)
 
2544
                {
 
2545
                    QStringList pages;
 
2546
 
 
2547
                    foreach(int page, bookmark->pages())
 
2548
                    {
 
2549
                        pages.append(QString::number(page));
 
2550
                    }
 
2551
 
 
2552
                    query.bindValue(0, QFileInfo(bookmark->filePath()).absoluteFilePath());
 
2553
                    query.bindValue(1, pages.join(","));
 
2554
 
 
2555
                    query.exec();
 
2556
 
 
2557
                    if(!query.isActive())
 
2558
                    {
 
2559
                        qDebug() << query.lastError();
 
2560
                        break;
 
2561
                    }
 
2562
                }
 
2563
            }
 
2564
        }
 
2565
 
 
2566
        m_database.commit();
 
2567
    }
 
2568
 
 
2569
#else
 
2570
 
 
2571
    QFile file(QDir(QFileInfo(m_settings->fileName()).path()).filePath("bookmarks.xml"));
 
2572
 
 
2573
    if(m_settings->mainWindow()->restoreBookmarks())
2179
2574
    {
2180
2575
        if(file.open(QIODevice::WriteOnly | QIODevice::Text))
2181
2576
        {
2200
2595
                        QDomElement jumpToPageElement = document.createElement("jumpToPage");
2201
2596
                        bookmarkElement.appendChild(jumpToPageElement);
2202
2597
 
2203
 
                        jumpToPageElement.setAttribute("page", page);                        
 
2598
                        jumpToPageElement.setAttribute("page", page);
2204
2599
                    }
2205
2600
                }
2206
2601
            }
2215
2610
    {
2216
2611
        file.remove();
2217
2612
    }
 
2613
 
 
2614
#endif // WITH_SQL
 
2615
}
 
2616
 
 
2617
void MainWindow::restorePerFileSettings(DocumentView* tab)
 
2618
{
 
2619
#ifdef WITH_SQL
 
2620
 
 
2621
    if(m_settings->mainWindow()->restorePerFileSettings() && m_database.isOpen() && tab != 0)
 
2622
    {
 
2623
        m_database.transaction();
 
2624
 
 
2625
        QSqlQuery query(m_database);
 
2626
        query.prepare("SELECT currentPage,continuousMode,layoutMode,scaleMode,scaleFactor,rotation FROM perfilesettings_v1 WHERE filePath==?");
 
2627
 
 
2628
        query.bindValue(0, QCryptographicHash::hash(QFileInfo(tab->filePath()).absoluteFilePath().toUtf8(), QCryptographicHash::Sha1).toBase64());
 
2629
 
 
2630
        query.exec();
 
2631
 
 
2632
        if(query.next())
 
2633
        {
 
2634
            tab->setContinousMode(query.value(1).toBool());
 
2635
            tab->setLayoutMode(static_cast< DocumentView::LayoutMode >(query.value(2).toUInt()));
 
2636
 
 
2637
            tab->setScaleMode(static_cast< DocumentView::ScaleMode >(query.value(3).toUInt()));
 
2638
            tab->setScaleFactor(query.value(4).toReal());
 
2639
 
 
2640
            tab->setRotation(static_cast< Poppler::Page::Rotation >(query.value(5).toUInt()));
 
2641
 
 
2642
            tab->jumpToPage(query.value(0).toInt(), false);
 
2643
        }
 
2644
 
 
2645
        if(!query.isActive())
 
2646
        {
 
2647
            qDebug() << query.lastError();
 
2648
        }
 
2649
 
 
2650
        m_database.commit();
 
2651
    }
 
2652
 
 
2653
#else
 
2654
 
 
2655
    Q_UNUSED(tab);
 
2656
 
 
2657
#endif // WITH_SQL
 
2658
}
 
2659
 
 
2660
void MainWindow::savePerFileSettings(const DocumentView* tab)
 
2661
{
 
2662
#ifdef WITH_SQL
 
2663
 
 
2664
    if(m_settings->mainWindow()->restorePerFileSettings() && m_database.isOpen() && tab != 0)
 
2665
    {
 
2666
        m_database.transaction();
 
2667
 
 
2668
        QSqlQuery query(m_database);
 
2669
        query.prepare("INSERT OR REPLACE INTO perfilesettings_v1 "
 
2670
                      "(lastUsed,filePath,currentPage,continuousMode,layoutMode,scaleMode,scaleFactor,rotation)"
 
2671
                      " VALUES (?,?,?,?,?,?,?,?)");
 
2672
 
 
2673
        query.bindValue(0, QDateTime::currentDateTime().toTime_t());
 
2674
 
 
2675
        query.bindValue(1, QCryptographicHash::hash(QFileInfo(tab->filePath()).absoluteFilePath().toUtf8(), QCryptographicHash::Sha1).toBase64());
 
2676
        query.bindValue(2, tab->currentPage());
 
2677
 
 
2678
        query.bindValue(3, static_cast< uint >(tab->continousMode()));
 
2679
        query.bindValue(4, static_cast< uint >(tab->layoutMode()));
 
2680
 
 
2681
        query.bindValue(5, static_cast< uint >(tab->scaleMode()));
 
2682
        query.bindValue(6, tab->scaleFactor());
 
2683
 
 
2684
        query.bindValue(7, static_cast< uint >(tab->rotation()));
 
2685
 
 
2686
        query.exec();
 
2687
 
 
2688
        if(!query.isActive())
 
2689
        {
 
2690
            qDebug() << query.lastError();
 
2691
        }
 
2692
 
 
2693
        m_database.commit();
 
2694
    }
 
2695
 
 
2696
#else
 
2697
 
 
2698
    Q_UNUSED(tab);
 
2699
 
 
2700
#endif // WITH_SQL
2218
2701
}
2219
2702
 
2220
2703
#ifdef WITH_DBUS
2223
2706
{
2224
2707
}
2225
2708
 
2226
 
bool MainWindowAdaptor::open(const QString& filePath, int page, const QRectF &highlight)
 
2709
bool MainWindowAdaptor::open(const QString& filePath, int page, const QRectF& highlight)
2227
2710
{
2228
2711
    return mainWindow()->open(filePath, page, highlight);
2229
2712
}
2230
2713
 
2231
 
bool MainWindowAdaptor::openInNewTab(const QString& filePath, int page, const QRectF &highlight)
 
2714
bool MainWindowAdaptor::openInNewTab(const QString& filePath, int page, const QRectF& highlight)
2232
2715
{
2233
2716
    return mainWindow()->openInNewTab(filePath, page, highlight);
2234
2717
}