File indexing completed on 2024-04-28 05:08:25

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   void slotFileNewByTemplate(const QString& collectionTemplate);
0154   /**
0155    * Opens a file and loads it into the document
0156    */
0157   void slotFileOpen();
0158   /**
0159    * Opens a file by URL and loads it into the document
0160    *
0161    * @param url The url to open
0162    */
0163   void slotFileOpen(const QUrl& url);
0164   /**
0165    * Opens a file from the recent files menu
0166    *
0167    * @param url The url sent by the RecentFilesAction
0168    */
0169   void slotFileOpenRecent(const QUrl& url);
0170   /**
0171    * Saves the document
0172    */
0173   void slotFileSave();
0174   /**
0175    * Saves a document by a new filename
0176    */
0177   void slotFileSaveAs();
0178   void slotFileSaveAsTemplate();
0179   /**
0180    * Prints the current document.
0181    */
0182   void slotFilePrint();
0183   void slotFilePrintPreview();
0184   /**
0185    * Quits the application.
0186    */
0187   void slotFileQuit();
0188   /**
0189    * Puts the marked text/object into the clipboard and removes it from the document.
0190    */
0191   void slotEditCut();
0192   /*
0193    * Puts the marked text/object into the clipboard.
0194    */
0195   void slotEditCopy();
0196   /**
0197    * Pastes the clipboard into the document.
0198    */
0199   void slotEditPaste();
0200   /**
0201    * Selects all the entries in the collection.
0202    */
0203   void slotEditSelectAll();
0204   /**
0205    * Deselects all the entries in the collection.
0206    */
0207   void slotEditDeselect();
0208   /**
0209    * Toggles the edit widget.
0210    */
0211   void slotToggleEntryEditor();
0212   /**
0213    * Shows the configuration dialog for the application.
0214    */
0215   void slotShowConfigDialog();
0216   /**
0217    * Hides the configuration dialog for the application.
0218    */
0219   void slotHideConfigDialog();
0220   /**
0221    * Shows the fetch dialog.
0222    */
0223   void slotShowFetchDialog();
0224   /**
0225    * Hides the fetch dialog.
0226    */
0227   void slotHideFetchDialog();
0228   /**
0229    * Changes the statusbar contents for the standard label permanently,
0230    * used to indicate current actions being made.
0231    *
0232    * @param text The text that is displayed in the statusbar
0233    */
0234   void slotStatusMsg(const QString& text);
0235   void slotClearStatus();
0236   /**
0237    * Updates the entry count in the status bar.
0238    */
0239   void slotEntryCount();
0240   /**
0241    * Handles updating everything when the configuration is changed
0242    * via the configuration dialog. This slot is called when the OK or Apply
0243    * button is clicked in the dialog
0244    */
0245   void slotHandleConfigChange();
0246   /**
0247    * Changes the grouping of the entries in the @ref GroupView. The current value
0248    * of the combobox in the toolbar is used.
0249    */
0250   void slotChangeGrouping();
0251   /**
0252    * Imports data.
0253    *
0254    * @param format The import format
0255    */
0256   void slotFileImport(int format);
0257   /**
0258    * Exports the current document.
0259    *
0260    * @param format The export format
0261    */
0262   void slotFileExport(int format);
0263   /**
0264    * Shows the filter dialog for the application.
0265    */
0266   void slotShowFilterDialog();
0267   /**
0268    * Hides the filter dialog for the application.
0269    */
0270   void slotHideFilterDialog();
0271   /**
0272    * Shows the collection properties dialog for the application.
0273    */
0274   void slotShowCollectionFieldsDialog();
0275   /**
0276    * Hides the collection properties dialog for the application.
0277    */
0278   void slotHideCollectionFieldsDialog();
0279   /**
0280    * Shows the string macro editor dialog for the application.
0281    */
0282   void slotShowStringMacroDialog();
0283   /**
0284    * Shows the citation key dialog
0285    */
0286   void slotShowBibtexKeyDialog();
0287   /**
0288    * Hides the citation key dialog
0289    */
0290   void slotHideBibtexKeyDialog();
0291   /**
0292    * Handle a url that indicates some action should be taken
0293    */
0294   void slotURLAction(const QUrl& url);
0295 
0296 private:
0297   /**
0298    * Saves the general options like all toolbar positions and status as well as the
0299    * geometry and the recent file list to the configuration file.
0300    */
0301   void saveOptions();
0302   /**
0303    * Reads the specific options.
0304    */
0305   void readOptions();
0306   /**
0307    * Initializes the QActions of the application
0308    */
0309   void initActions();
0310   /**
0311    * Sets up the statusbar for the main window by initializing a status label
0312    * and inserting a progress bar and entry counter.
0313    */
0314   void initStatusBar();
0315   /**
0316    * Initiates the view, setting up all the dock windows and so on.
0317    */
0318   void initView();
0319   /**
0320    * Initiates the document.
0321    */
0322   void initDocument();
0323   /**
0324    * Initiates all the signal and slot connections between major objects in the view.
0325    */
0326   void initConnections();
0327 
0328   bool querySaveModified();
0329 
0330   /**
0331    * Called before the window is closed, either by the user or indirectly by the
0332    * session manager.
0333    *
0334    * The purpose of this function is to prepare the window in a way that it is safe to close it,
0335    * i.e. without the user losing some data.
0336    * @see KMainWindow::queryClose
0337    */
0338   bool queryClose() Q_DECL_OVERRIDE;
0339   /**
0340    * Actual method used when opening a URL. Updating for the list views is turned off
0341    * as well as sorting, in order to more quickly load the document.
0342    *
0343    * @param url The url to open
0344    */
0345   bool openURL(const QUrl& url);
0346   enum PrintAction { Print, PrintPreview };
0347   /*
0348    * Helper method to handle the printing duties.
0349    *
0350    * @param html The HTML string representing the doc to print
0351    */
0352   void doPrint(PrintAction action);
0353 
0354   void XSLTError();
0355   /**
0356    * Helper function to activate a slot in the edit widget.
0357    * Primarily used for copy, cut, and paste.
0358    *
0359    * @param slot The slot name
0360    */
0361   void activateEditSlot(const char* slot);
0362   void addFilterView();
0363   void addLoanView();
0364   void updateCaption(bool modified);
0365   void updateCollectionActions();
0366   void updateEntrySources();
0367 
0368 private Q_SLOTS:
0369   /**
0370    * Updates the actions when a file is opened.
0371    */
0372   void slotEnableOpenedActions();
0373   /**
0374    * Updates the save action and the caption when the document is modified.
0375    */
0376   void slotEnableModifiedActions(bool modified = true);
0377   /**
0378    * Read the options specific to a collection
0379    *
0380    * @param coll The collection pointer
0381    */
0382   void readCollectionOptions(Tellico::Data::CollPtr coll);
0383   /**
0384    * Saves the options relevant for a collection. I was having problems with the collection
0385    * being destructed before I could save info.
0386    *
0387    * @param coll A pointer to the collection
0388    */
0389   void saveCollectionOptions(Tellico::Data::CollPtr coll);
0390   /**
0391    * Queue a filter update. The timer adds a 200 millisecond delay before actually
0392    * updating the filter.
0393    */
0394   void slotQueueFilter();
0395   /**
0396    * Update the filter to match any field with text. If a non-word character appears, the
0397    * text is interpreted as a regexp.
0398    */
0399   void slotCheckFilterQueue();
0400   void slotUpdateFilter(Tellico::FilterPtr filter);
0401   /**
0402    * Updates the collection toolbar.
0403    */
0404   void slotUpdateCollectionToolBar(Tellico::Data::CollPtr coll);
0405   /**
0406    * Make sure the edit dialog is visible and start a new entry.
0407    */
0408   void slotNewEntry();
0409   /**
0410    * Handle the entry editor dialog being closed.
0411    */
0412   void slotEditDialogFinished();
0413   /**
0414    * Handle the Ok button being clicked in the string macros dialog.
0415    */
0416   void slotStringMacroDialogFinished(int result=-1);
0417   /**
0418    * Since I use an application icon in the toolbar, I need to change its size whenever
0419    * the toolbar changes mode
0420    */
0421   void slotUpdateToolbarIcons();
0422   /**
0423    * Convert current collection to a bibliography.
0424    */
0425   void slotConvertToBibliography();
0426   /**
0427    * Send a citation for the selected entries
0428    */
0429   void slotCiteEntry(int action);
0430   /**
0431    * Show the entry editor and update menu item.
0432    */
0433   void slotShowEntryEditor();
0434   /**
0435    * Show the report window.
0436    */
0437   void slotShowReportDialog();
0438   /**
0439    * Show the report window.
0440    */
0441   void slotHideReportDialog();
0442   /**
0443    * Focus the filter
0444    */
0445   void slotGroupLabelActivated();
0446   void slotFilterLabelActivated();
0447   void slotClearFilter();
0448   void slotRenameCollection();
0449   void slotImageLocationMismatch();
0450   void slotImageLocationChanged();
0451   /**
0452    * Toggle full screen mode
0453    */
0454   void slotToggleFullScreen();
0455   /**
0456    * Toggle menubar visibility
0457    */
0458   void slotToggleMenuBarVisibility();
0459   void slotToggleLayoutLock(bool lock);
0460   void slotResetLayout();
0461   void guiFactoryReset();
0462   void showLog();
0463 
0464 private:
0465   void importFile(Import::Format format, const QList<QUrl>& kurls);
0466   void importText(Import::Format format, const QString& text);
0467   bool importCollection(Data::CollPtr coll, Import::Action action);
0468 
0469   // the reason that I have to keep pointers to all these
0470   // is because they get plugged into menus later in Controller
0471   KRecentFilesAction* m_fileOpenRecent;
0472   QAction* m_fileSave;
0473   QAction* m_newEntry;
0474   QAction* m_editEntry;
0475   QAction* m_copyEntry;
0476   QAction* m_deleteEntry;
0477   QAction* m_mergeEntry;
0478   KActionMenu* m_updateEntryMenu;
0479   QAction* m_updateAll;
0480   QAction* m_checkInEntry;
0481   QAction* m_checkOutEntry;
0482   KToggleAction* m_toggleEntryEditor;
0483   KDualAction* m_lockLayout;
0484   KActionMenu* m_newCollectionMenu;
0485 
0486   KSelectAction* m_entryGrouping;
0487   GUI::LineEdit* m_quickFilter;
0488 
0489   QMainWindow* m_dummyWindow;
0490   GUI::DockWidget* m_groupViewDock;
0491   GUI::DockWidget* m_collectionViewDock;
0492 
0493   Tellico::StatusBar* m_statusBar;
0494 
0495   DetailedListView* m_detailedView;
0496   EntryEditDialog* m_editDialog;
0497   GUI::TabWidget* m_viewTabs;
0498   GroupView* m_groupView;
0499   FilterView* m_filterView;
0500   LoanView* m_loanView;
0501   EntryView* m_entryView;
0502   EntryIconView* m_iconView;
0503   ViewStack* m_viewStack;
0504   QSignalMapper* m_updateMapper;
0505 
0506   ConfigDialog* m_configDlg;
0507   FilterDialog* m_filterDlg;
0508   CollectionFieldsDialog* m_collFieldsDlg;
0509   StringMapDialog* m_stringMacroDlg;
0510   BibtexKeyDialog* m_bibtexKeyDlg;
0511   FetchDialog* m_fetchDlg;
0512   ReportDialog* m_reportDlg;
0513 
0514   QList<QAction*> m_fetchActions;
0515 
0516   // keep track of the number of queued filter updates
0517   uint m_queuedFilters;
0518 
0519   // keep track whether everything gets initialized
0520   bool m_initialized;
0521   // need to keep track of whether the current collection has never been saved
0522   bool m_newDocument;
0523   // Don't queue filter if true
0524   bool m_dontQueueFilter;
0525   bool m_savingImageLocationChange;
0526 };
0527 
0528 } // end namespace
0529 #endif // TELLICO_MAINWINDOW_H