File indexing completed on 2024-04-28 16:32:04

0001 /***************************************************************************
0002     Copyright (C) 2001-2009 Robby Stephenson <robby@periapsis.org>
0003     Copyright (C) 2011 Pedro Miguel Carvalho <kde@pmc.com.pt>
0004  ***************************************************************************/
0005 
0006 /***************************************************************************
0007  *                                                                         *
0008  *   This program is free software; you can redistribute it and/or         *
0009  *   modify it under the terms of the GNU General Public License as        *
0010  *   published by the Free Software Foundation; either version 2 of        *
0011  *   the License or (at your option) version 3 or any later version        *
0012  *   accepted by the membership of KDE e.V. (or its successor approved     *
0013  *   by the membership of KDE e.V.), which shall act as a proxy            *
0014  *   defined in Section 14 of version 3 of the license.                    *
0015  *                                                                         *
0016  *   This program is distributed in the hope that it will be useful,       *
0017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0019  *   GNU General Public License for more details.                          *
0020  *                                                                         *
0021  *   You should have received a copy of the GNU General Public License     *
0022  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
0023  *                                                                         *
0024  ***************************************************************************/
0025 
0026 #ifndef TELLICO_MAINWINDOW_H
0027 #define TELLICO_MAINWINDOW_H
0028 
0029 #include <config.h>
0030 
0031 #include "translators/translators.h"
0032 #include "datavectors.h"
0033 
0034 #include <KXmlGuiWindow>
0035 
0036 #include <QUrl>
0037 #include <QList>
0038 
0039 class KToolBar;
0040 class QAction;
0041 class KSelectAction;
0042 class KToggleAction;
0043 class KDualAction;
0044 class KRecentFilesAction;
0045 class KActionMenu;
0046 
0047 class QCloseEvent;
0048 class QDockWidget;
0049 class QSignalMapper;
0050 
0051 namespace Tellico {
0052 // forward declarations
0053   namespace GUI {
0054     class LineEdit;
0055     class TabWidget;
0056     class DockWidget;
0057   }
0058   class Controller;
0059   class ViewStack;
0060   class DetailedListView;
0061   class EntryIconView;
0062   class EntryView;
0063   class FilterDialog;
0064   class EntryEditDialog;
0065   class GroupView;
0066   class FilterView;
0067   class LoanView;
0068   class ConfigDialog;
0069   class CollectionFieldsDialog;
0070   class StringMapDialog;
0071   class BibtexKeyDialog;
0072   class EntryItem;
0073   class FetchDialog;
0074   class ReportDialog;
0075   class StatusBar;
0076   class DropHandler;
0077 
0078 /**
0079  * The base class for Tellico application windows. It sets up the main
0080  * window and reads the config file as well as providing a menubar, toolbar
0081  * and statusbar. Tellico reimplements the methods that KMainWindow provides
0082  * for main window handling and supports full session management as well as
0083  * using QActions.
0084  *
0085  * @author Robby Stephenson
0086  */
0087 class MainWindow : public KXmlGuiWindow {
0088 Q_OBJECT
0089 
0090 friend class Controller;
0091 friend class DropHandler;
0092 
0093 public:
0094   /**
0095    * The main window constructor, calls all init functions to create the application.
0096    */
0097   MainWindow(QWidget* parent=nullptr);
0098   ~MainWindow();
0099 
0100   /**
0101    * Opens the initial file.
0102    *
0103    * @param nofile If true, even if the config option to reopen last file is set, no file is opened
0104    */
0105   void initFileOpen(bool nofile);
0106   /**
0107    * Saves the document
0108    *
0109    * @return Returns @p true if successful
0110    */
0111   bool fileSave();
0112   /**
0113    * Saves a document by a new filename
0114    *
0115    * @return Returns @p true if successful
0116    */
0117   bool fileSaveAs();
0118   /**
0119    * @return Returns whether the current collection is still the non-saved default one
0120    */
0121   bool isNewDocument() const { return m_newDocument; }
0122   /**
0123    * Used by main() and DBUS to import file.
0124    *
0125    * @param format The file format
0126    * @param url The url
0127    */
0128   virtual bool importFile(Import::Format format, const QUrl& url, Import::Action action);
0129   /**
0130    * Used by DBUS to export to a file.
0131    */
0132   virtual bool exportCollection(Export::Format format, const QUrl& url, bool filtered);
0133   /**
0134    * Used by DBUS
0135    */
0136   virtual void openFile(const QString& file);
0137   virtual void setFilter(const QString& text);
0138   virtual bool showEntry(Data::ID id);
0139 
0140   bool eventFilter(QObject* watched, QEvent* event) Q_DECL_OVERRIDE;
0141 
0142 public Q_SLOTS:
0143   /**
0144    * Initializes some stuff after the object is created.
0145    */
0146   void slotInit();
0147   /**
0148    * Cleans up everything and then opens a new document.
0149    *
0150    * @param type Type of collection to add
0151    */
0152   void slotFileNew(int type);
0153   /**
0154    * Opens a file and loads it into the document
0155    */
0156   void slotFileOpen();
0157   /**
0158    * Opens a file by URL and loads it into the document
0159    *
0160    * @param url The url to open
0161    */
0162   void slotFileOpen(const QUrl& url);
0163   /**
0164    * Opens a file from the recent files menu
0165    *
0166    * @param url The url sent by the RecentFilesAction
0167    */
0168   void slotFileOpenRecent(const QUrl& url);
0169   /**
0170    * Saves the document
0171    */
0172   void slotFileSave();
0173   /**
0174    * Saves a document by a new filename
0175    */
0176   void slotFileSaveAs();
0177   /**
0178    * Prints the current document.
0179    */
0180   void slotFilePrint();
0181   void slotFilePrintPreview();
0182   /**
0183    * Quits the application.
0184    */
0185   void slotFileQuit();
0186   /**
0187    * Puts the marked text/object into the clipboard and removes it from the document.
0188    */
0189   void slotEditCut();
0190   /*
0191    * Puts the marked text/object into the clipboard.
0192    */
0193   void slotEditCopy();
0194   /**
0195    * Pastes the clipboard into the document.
0196    */
0197   void slotEditPaste();
0198   /**
0199    * Selects all the entries in the collection.
0200    */
0201   void slotEditSelectAll();
0202   /**
0203    * Deselects all the entries in the collection.
0204    */
0205   void slotEditDeselect();
0206   /**
0207    * Toggles the edit widget.
0208    */
0209   void slotToggleEntryEditor();
0210   /**
0211    * Shows the configuration dialog for the application.
0212    */
0213   void slotShowConfigDialog();
0214   /**
0215    * Hides the configuration dialog for the application.
0216    */
0217   void slotHideConfigDialog();
0218   /**
0219    * Shows the fetch dialog.
0220    */
0221   void slotShowFetchDialog();
0222   /**
0223    * Hides the fetch dialog.
0224    */
0225   void slotHideFetchDialog();
0226   /**
0227    * Changes the statusbar contents for the standard label permanently,
0228    * used to indicate current actions being made.
0229    *
0230    * @param text The text that is displayed in the statusbar
0231    */
0232   void slotStatusMsg(const QString& text);
0233   void slotClearStatus();
0234   /**
0235    * Updates the entry count in the status bar.
0236    */
0237   void slotEntryCount();
0238   /**
0239    * Handles updating everything when the configuration is changed
0240    * via the configuration dialog. This slot is called when the OK or Apply
0241    * button is clicked in the dialog
0242    */
0243   void slotHandleConfigChange();
0244   /**
0245    * Changes the grouping of the entries in the @ref GroupView. The current value
0246    * of the combobox in the toolbar is used.
0247    */
0248   void slotChangeGrouping();
0249   /**
0250    * Imports data.
0251    *
0252    * @param format The import format
0253    */
0254   void slotFileImport(int format);
0255   /**
0256    * Exports the current document.
0257    *
0258    * @param format The export format
0259    */
0260   void slotFileExport(int format);
0261   /**
0262    * Shows the filter dialog for the application.
0263    */
0264   void slotShowFilterDialog();
0265   /**
0266    * Hides the filter dialog for the application.
0267    */
0268   void slotHideFilterDialog();
0269   /**
0270    * Shows the collection properties dialog for the application.
0271    */
0272   void slotShowCollectionFieldsDialog();
0273   /**
0274    * Hides the collection properties dialog for the application.
0275    */
0276   void slotHideCollectionFieldsDialog();
0277   /**
0278    * Shows the "Tip of the Day" dialog.
0279    *
0280    * @param force Whether the configuration setting should be ignored
0281    */
0282   void slotShowTipOfDay(bool force=true);
0283   /**
0284    * Shows the string macro editor dialog for the application.
0285    */
0286   void slotShowStringMacroDialog();
0287   /**
0288    * Shows the citation key dialog
0289    */
0290   void slotShowBibtexKeyDialog();
0291   /**
0292    * Hides the citation key dialog
0293    */
0294   void slotHideBibtexKeyDialog();
0295   /**
0296    * Handle a url that indicates some actino should be taken
0297    */
0298   void slotURLAction(const QUrl& url);
0299 
0300 private:
0301   /**
0302    * Saves the general options like all toolbar positions and status as well as the
0303    * geometry and the recent file list to the configuration file.
0304    */
0305   void saveOptions();
0306   /**
0307    * Reads the specific options.
0308    */
0309   void readOptions();
0310   /**
0311    * Initializes the QActions of the application
0312    */
0313   void initActions();
0314   /**
0315    * Sets up the statusbar for the main window by initializing a status label
0316    * and inserting a progress bar and entry counter.
0317    */
0318   void initStatusBar();
0319   /**
0320    * Initiates the view, setting up all the dock windows and so on.
0321    */
0322   void initView();
0323   /**
0324    * Initiates the document.
0325    */
0326   void initDocument();
0327   /**
0328    * Initiates all the signal and slot connections between major objects in the view.
0329    */
0330   void initConnections();
0331 
0332   bool querySaveModified();
0333 
0334   /**
0335    * Called before the window is closed, either by the user or indirectly by the
0336    * session manager.
0337    *
0338    * The purpose of this function is to prepare the window in a way that it is safe to close it,
0339    * i.e. without the user losing some data.
0340    * @see KMainWindow::queryClose
0341    */
0342   bool queryClose() Q_DECL_OVERRIDE;
0343   /**
0344    * Actual method used when opening a URL. Updating for the list views is turned off
0345    * as well as sorting, in order to more quickly load the document.
0346    *
0347    * @param url The url to open
0348    */
0349   bool openURL(const QUrl& url);
0350   enum PrintAction { Print, PrintPreview };
0351   /*
0352    * Helper method to handle the printing duties.
0353    *
0354    * @param html The HTML string representing the doc to print
0355    */
0356   void doPrint(PrintAction action);
0357 
0358   void XSLTError();
0359   /**
0360    * Helper function to activate a slot in the edit widget.
0361    * Primarily used for copy, cut, and paste.
0362    *
0363    * @param slot The slot name
0364    */
0365   void activateEditSlot(const char* slot);
0366   void addFilterView();
0367   void addLoanView();
0368   void updateCaption(bool modified);
0369   void updateCollectionActions();
0370   void updateEntrySources();
0371 
0372 private Q_SLOTS:
0373   /**
0374    * Updates the actions when a file is opened.
0375    */
0376   void slotEnableOpenedActions();
0377   /**
0378    * Updates the save action and the caption when the document is modified.
0379    */
0380   void slotEnableModifiedActions(bool modified = true);
0381   /**
0382    * Read the options specific to a collection
0383    *
0384    * @param coll The collection pointer
0385    */
0386   void readCollectionOptions(Tellico::Data::CollPtr coll);
0387   /**
0388    * Saves the options relevant for a collection. I was having problems with the collection
0389    * being destructed before I could save info.
0390    *
0391    * @param coll A pointer to the collection
0392    */
0393   void saveCollectionOptions(Tellico::Data::CollPtr coll);
0394   /**
0395    * Queue a filter update. The timer adds a 200 millisecond delay before actually
0396    * updating the filter.
0397    */
0398   void slotQueueFilter();
0399   /**
0400    * Update the filter to match any field with text. If a non-word character appears, the
0401    * text is interpreted as a regexp.
0402    */
0403   void slotCheckFilterQueue();
0404   void slotUpdateFilter(Tellico::FilterPtr filter);
0405   /**
0406    * Updates the collection toolbar.
0407    */
0408   void slotUpdateCollectionToolBar(Tellico::Data::CollPtr coll);
0409   /**
0410    * Make sure the edit dialog is visible and start a new entry.
0411    */
0412   void slotNewEntry();
0413   /**
0414    * Handle the entry editor dialog being closed.
0415    */
0416   void slotEditDialogFinished();
0417   /**
0418    * Handle the Ok button being clicked in the string macros dialog.
0419    */
0420   void slotStringMacroDialogFinished(int result=-1);
0421   /**
0422    * Since I use an application icon in the toolbar, I need to change its size whenever
0423    * the toolbar changes mode
0424    */
0425   void slotUpdateToolbarIcons();
0426   /**
0427    * Convert current collection to a bibliography.
0428    */
0429   void slotConvertToBibliography();
0430   /**
0431    * Send a citation for the selected entries
0432    */
0433   void slotCiteEntry(int action);
0434   /**
0435    * Show the entry editor and update menu item.
0436    */
0437   void slotShowEntryEditor();
0438   /**
0439    * Show the report window.
0440    */
0441   void slotShowReportDialog();
0442   /**
0443    * Show the report window.
0444    */
0445   void slotHideReportDialog();
0446   /**
0447    * Focus the filter
0448    */
0449   void slotGroupLabelActivated();
0450   void slotFilterLabelActivated();
0451   void slotClearFilter();
0452   void slotRenameCollection();
0453   void slotImageLocationMismatch();
0454   void slotImageLocationChanged();
0455   /**
0456    * Toggle full screen mode
0457    */
0458   void slotToggleFullScreen();
0459   /**
0460    * Toggle menubar visibility
0461    */
0462   void slotToggleMenuBarVisibility();
0463   void slotToggleLayoutLock(bool lock);
0464   void slotResetLayout();
0465   void guiFactoryReset();
0466 
0467 private:
0468   void importFile(Import::Format format, const QList<QUrl>& kurls);
0469   void importText(Import::Format format, const QString& text);
0470   bool importCollection(Data::CollPtr coll, Import::Action action);
0471 
0472   // the reason that I have to keep pointers to all these
0473   // is because they get plugged into menus later in Controller
0474   KRecentFilesAction* m_fileOpenRecent;
0475   QAction* m_fileSave;
0476   QAction* m_newEntry;
0477   QAction* m_editEntry;
0478   QAction* m_copyEntry;
0479   QAction* m_deleteEntry;
0480   QAction* m_mergeEntry;
0481   KActionMenu* m_updateEntryMenu;
0482   QAction* m_updateAll;
0483   QAction* m_checkInEntry;
0484   QAction* m_checkOutEntry;
0485   KToggleAction* m_toggleEntryEditor;
0486   KDualAction* m_lockLayout;
0487 
0488   KSelectAction* m_entryGrouping;
0489   GUI::LineEdit* m_quickFilter;
0490 
0491   QMainWindow* m_dummyWindow;
0492   GUI::DockWidget* m_groupViewDock;
0493   GUI::DockWidget* m_collectionViewDock;
0494 
0495   Tellico::StatusBar* m_statusBar;
0496 
0497   DetailedListView* m_detailedView;
0498   EntryEditDialog* m_editDialog;
0499   GUI::TabWidget* m_viewTabs;
0500   GroupView* m_groupView;
0501   FilterView* m_filterView;
0502   LoanView* m_loanView;
0503   EntryView* m_entryView;
0504   EntryIconView* m_iconView;
0505   ViewStack* m_viewStack;
0506   QSignalMapper* m_updateMapper;
0507 
0508   ConfigDialog* m_configDlg;
0509   FilterDialog* m_filterDlg;
0510   CollectionFieldsDialog* m_collFieldsDlg;
0511   StringMapDialog* m_stringMacroDlg;
0512   BibtexKeyDialog* m_bibtexKeyDlg;
0513   FetchDialog* m_fetchDlg;
0514   ReportDialog* m_reportDlg;
0515 
0516   QList<QAction*> m_fetchActions;
0517 
0518   // keep track of the number of queued filter updates
0519   uint m_queuedFilters;
0520 
0521   // keep track whether everything gets initialized
0522   bool m_initialized;
0523   // need to keep track of whether the current collection has never been saved
0524   bool m_newDocument;
0525   // Don't queue filter if true
0526   bool m_dontQueueFilter;
0527   bool m_savingImageLocationChange;
0528 };
0529 
0530 } // end namespace
0531 #endif // TELLICO_MAINWINDOW_H