File indexing completed on 2024-05-12 16:39:37

0001 /* This file is part of the KDE project
0002    Copyright (C) 2003 Lucijan Busch <lucijan@kde.org>
0003    Copyright (C) 2003-2014 Jarosław Staniek <staniek@kde.org>
0004 
0005    This library is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU Library General Public
0007    License as published by the Free Software Foundation; either
0008    version 2 of the License, or (at your option) any later version.
0009 
0010    This library is distributed in the hope that it will be useful,
0011    but WITHOUT ANY WARRANTY; without even the implied warranty of
0012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013    Library General Public License for more details.
0014 
0015    You should have received a copy of the GNU Library General Public License
0016    along with this library; see the file COPYING.LIB.  If not, write to
0017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018  * Boston, MA 02110-1301, USA.
0019 */
0020 
0021 #ifndef KEXIMAINWINDOWIFACE_H
0022 #define KEXIMAINWINDOWIFACE_H
0023 
0024 //#define KEXI_IMPL_WARNINGS
0025 
0026 #include <QMap>
0027 
0028 #include <kexi_global.h>
0029 #include <KDbTristate>
0030 
0031 #include "KexiMigrateManagerInterface.h"
0032 #include "kexisharedactionhost.h"
0033 #include "kexi.h"
0034 
0035 class KDbQuerySchema;
0036 
0037 class KexiWindow;
0038 class KexiProject;
0039 class KActionCollection;
0040 class KexiSearchableModel;
0041 class KexiUserFeedbackAgent;
0042 class KexiMigrateManagerInterface;
0043 namespace KexiPart
0044 {
0045 class Item;
0046 class Info;
0047 }
0048 class KToolBar;
0049 
0050 /**
0051  * @short Kexi's main window interface
0052  * This interface is implemented by KexiMainWindow class.
0053  * KexiMainWindow offers simple features what lowers cross-dependency (and also avoids
0054  * circular dependencies between Kexi modules).
0055  */
0056 class KEXICORE_EXPORT KexiMainWindowIface : public KexiSharedActionHost
0057 {
0058 public:
0059     //! Used by printActionForItem()
0060     enum PrintActionType {
0061         PrintItem,
0062         PreviewItem,
0063         PageSetupForItem
0064     };
0065 
0066     KexiMainWindowIface();
0067     virtual ~KexiMainWindowIface();
0068 
0069     //! \return KexiMainWindowImpl global singleton (if it is instantiated)
0070     static KexiMainWindowIface* global();
0071 
0072     QWidget* thisWidget();
0073 
0074     //! Project data of currently opened project or NULL if no project here yet.
0075     virtual KexiProject *project() = 0;
0076 
0077 //! @todo KEXI3 virtual KActionCollection* actionCollection() const = 0;
0078     virtual KActionCollection* actionCollection() const = 0;
0079 
0080 //! @todo KEXI3 virtual QWidget* focusWidget() const = 0;
0081     virtual QWidget* focusWidget() const = 0;
0082 
0083     /*! Registers window \a window for watching and adds it to the main window's stack. */
0084     virtual void registerChild(KexiWindow *window) = 0;
0085 
0086     /*! \return a list of all actions defined by application.
0087      Not all of them are shared. Don't use plug these actions
0088      in your windows by hand but user methods from KexiView! */
0089     virtual QList<QAction*> allActions() const = 0;
0090 
0091     /*! \return currently active window or 0 if there is no active window. */
0092     virtual KexiWindow* currentWindow() const = 0;
0093 
0094     /*! Switches \a window to view \a mode.
0095      Activates the window if it is not the current window. */
0096     virtual tristate switchToViewMode(KexiWindow& window, Kexi::ViewMode viewMode) = 0;
0097 
0098     /*! \return true if this window is in the User Mode. */
0099     virtual bool userMode() const = 0;
0100 
0101 // Q_SIGNALS:
0102     //! Emitted to make sure the project can be close.
0103     //! Connect a slot here and set \a cancel to true to cancel the closing.
0104     virtual void acceptProjectClosingRequested(bool *cancel) = 0;
0105 
0106     //! Emitted before closing the project (and destroying all it's data members).
0107     //! You can do you cleanup of your structures here.
0108     virtual void beforeProjectClosing() = 0;
0109 
0110     //! Emitted after closing the project.
0111     virtual void projectClosed() = 0;
0112 
0113 // public Q_SLOTS:
0114     /*! Creates new object of type defined by \a info part info.
0115      \a openingCancelled is set to true if opening has been cancelled.
0116      \return true on success. */
0117     virtual bool newObject(KexiPart::Info *info, bool *openingCancelled) = 0;
0118 
0119     //! Opens object pointed by \a item in a view \a viewMode
0120     virtual KexiWindow* openObject(KexiPart::Item *item, Kexi::ViewMode viewMode,
0121                                    bool *openingCancelled, QMap<QString, QVariant>* staticObjectArgs = 0,
0122                                    QString* errorMessage = 0) = 0;
0123 
0124     //! For convenience
0125     virtual KexiWindow* openObject(const QString& mime, const QString& name,
0126                                    Kexi::ViewMode viewMode, bool *openingCancelled,
0127                                    QMap<QString, QVariant>* staticObjectArgs = 0) = 0;
0128 
0129     /*! Closes the object for \a item.
0130      \return true on success (closing can be dealyed though), false on failure and cancelled
0131      if the object has "opening" job assigned. */
0132     virtual tristate closeObject(KexiPart::Item* item) = 0;
0133 
0134     /*! Called to accept property butter editing. */
0135     virtual void acceptPropertySetEditing() = 0;
0136 
0137     /*! Received information from active view that \a window has switched
0138     its property set, so property editor contents should be reloaded.
0139      If \a force is true, property editor's data is reloaded even
0140      if the currently pointed property set is the same as before.
0141      If \a preservePrevSelection is true and there was a property set
0142      set before call, previously selected item will be preselected
0143      in the editor (if found). */
0144     virtual void propertySetSwitched(KexiWindow *window, bool force = false,
0145                                      bool preservePrevSelection = true,
0146                                      bool sortedProperties = false,
0147                                      const QByteArray& propertyToSelect = QByteArray()) = 0;
0148 
0149     //! Options used in saveObject()
0150     enum SaveObjectOption
0151     {
0152         DoNotAsk = 1,    //!< Do not ask for confirmation of overwriting
0153         SaveObjectAs = 2 //!< Saving object with a new name
0154     };
0155     Q_DECLARE_FLAGS(SaveObjectOptions, SaveObjectOption)
0156 
0157     /*! Saves window's \a window data. If window's data is never saved,
0158      user is asked for name and title, before saving (see getNewObjectInfo()).
0159      \return true on successul saving or false on error.
0160      If saving was cancelled by user, cancelled is returned.
0161      \a messageWhenAskingForName is a i18n'ed text that will be visible
0162      within name/caption dialog (see KexiNameDialog), which is popped
0163      up for never saved objects.
0164      Saving object with a new name is also supported here, to do so
0165      SaveObjectOption::SaveObjectAs should be added to @a options. */
0166     virtual tristate saveObject(KexiWindow *window,
0167                                 const QString& messageWhenAskingForName = QString(),
0168                                 SaveObjectOptions options = 0) = 0;
0169 
0170     /*! Closes window \a window. If window's data (see KexiWindow::isDirty()) is unsaved,
0171      used will be asked if saving should be perforemed.
0172      \return true on successull closing or false on closing error.
0173      If closing was cancelled by user, cancelled is returned.
0174      If \a window is 0, the current one will be closed. */
0175     virtual tristate closeWindow(KexiWindow *window) = 0;
0176 
0177     /*! Find window for a given \a identifier.
0178      \return 0 if no windows found. */
0179     virtual KexiWindow *openedWindowFor(int identifier) = 0;
0180 
0181     /*! Find window for a given \a item.
0182      \return 0 if no windows found. */
0183     virtual KexiWindow *openedWindowFor(const KexiPart::Item* item) = 0;
0184 
0185     /*! Parametrs for query with given id. */
0186     virtual QList<QVariant> currentParametersForQuery(int queryId) const = 0;
0187 
0188     //! \return query schema currently unsaved (edited) in a window corresponding to Kexi object identified by \a identifier.
0189     /*! For implementation in plugins, default implementation returns 0.
0190      * In implementations 0 should be returned if there is no such Kexi object
0191      * in the current project or if the object's window is not opened or if
0192      * the window contains no edited query at the moment.
0193      * If the query is "unsaved" the window displaying the corresponding Kexi object is marked as "dirty".
0194      * Currently supported type of Kexi objects are only queries being in data view.
0195      * See KexiQueryPart::unsavedQuery(int) for this implementation.
0196      * The query schema returned by this method can be used for example by data
0197      * exporting routines so users can export result of running unsaved
0198      * query without prior saving its design.
0199      * The changes to design can be even discarded without consequences this way.
0200     @note Returned pointer leads to a temporary query schema object owned by the corresponding view,
0201      * so lifetime of the object is limited to the lifetime of the view and its window.
0202      * Do not store the pointer after the window is closed to avoid dangling pointers.
0203     \see KexiPart::Part::currentQuery(KexiView*) KexiWindow::isDirty()
0204     */
0205     virtual KDbQuerySchema* unsavedQuery(int identifier) = 0;
0206 
0207     /*! Displays a dialog for entering object's name and title.
0208      Used on new object saving.
0209      \return true on successul closing or cancelled on cancel returned.
0210      It's unlikely to have false returned here.
0211      \a messageWhenAskingForName is a i18n'ed text that will be visible
0212      within name/caption dialog (see KexiNameDialog).
0213      If \a allowOverwriting is true, user will be asked for existing
0214      object's overwriting, else it will be impossible to enter
0215      a name of existing object.
0216      You can check \a overwriteNeeded after calling this method.
0217      If it's true, user agreed on overwriting, if it's false, user picked
0218      nonexisting name, so no overwrite will be needed.
0219      If \a originalName is not empty, the dialog will make sure the entered name
0220      is different, what is useful for "Saving As" objects.
0221     */
0222     virtual tristate getNewObjectInfo(KexiPart::Item *partItem,
0223                                       const QString &originalName,
0224                                       KexiPart::Part *part,
0225                                       bool allowOverwriting,
0226                                       bool *overwriteNeeded,
0227                                       const QString& messageWhenAskingForName = QString()) = 0;
0228 
0229     /*! Highlights object of mime \a mime and name \a name.
0230      This can be done in the Project Navigator or so.
0231      If a window for the object is opened (in any mode), it should be raised. */
0232     virtual void highlightObject(const QString& mime, const QString& name) = 0;
0233 
0234     //! Shows "print" dialog for \a item.
0235     //! \return true on success.
0236     virtual tristate printItem(KexiPart::Item* item) = 0;
0237 
0238     //! Shows "print preview" window.
0239     //! \return true on success.
0240     virtual tristate printPreviewForItem(KexiPart::Item* item) = 0;
0241 
0242     //! Shows "page setup" window for \a item.
0243     //! \return true on success and cancelled when the action was cancelled.
0244     virtual tristate showPageSetupForItem(KexiPart::Item* item) = 0;
0245 
0246     /*! Executes custom action for the main window, usually provided by a plugin.
0247      Also used by KexiFormEventAction. */
0248     virtual tristate executeCustomActionForObject(KexiPart::Item* item, const QString& actionName) = 0;
0249 
0250 //! @todo temporary solution before the tabbed toolbar framework emerges
0251     /*! Appends widget @a widget to tabbed toolbar declared as @a name.
0252      @a widget will be reparented but the ownership is not taken. */
0253     virtual void appendWidgetToToolbar(const QString& name, QWidget* widget) = 0;
0254 
0255 //! @todo temporary solution before the tabbed toolbar framework emerges
0256     /*! Shows or hides widget in the tabbed toolbar. */
0257     virtual void setWidgetVisibleInToolbar(QWidget* widget, bool visible) = 0;
0258 
0259 //! @todo replace with the final Actions API
0260     virtual void addToolBarAction(const QString& toolBarName, QAction *action) = 0;
0261 
0262 //! @todo replace with the final Actions API
0263     virtual KToolBar *toolBar(const QString& name) const = 0;
0264 
0265     /*! Updates info label of the property editor by reusing properties provided
0266      by the current property set.
0267      Read documentation of KexiPropertyEditorView class for information about accepted properties.
0268      If the current property is 0 and @a textToDisplayForNullSet string is not empty, this string is displayed
0269      (without icon or any other additional part).
0270      If the current property is 0 and @a textToDisplayForNullSet string is empty, the info label widget becomes
0271      hidden. */
0272     virtual void updatePropertyEditorInfoLabel(const QString& textToDisplayForNullSet = QString()) = 0;
0273 
0274     /*! Add searchable model to the main window. This extends search to a new area.
0275      One example is Project Navigator. */
0276     virtual void addSearchableModel(KexiSearchableModel *model) = 0;
0277 
0278     /*! Removes searchable model from the main window. @a model is not deleted. */
0279     virtual void removeSearchableModel(KexiSearchableModel *model) = 0;
0280 
0281     virtual KexiUserFeedbackAgent* userFeedbackAgent() const = 0;
0282 
0283     //! Interface to the migrate manager
0284     virtual KexiMigrateManagerInterface* migrateManager() = 0;
0285 
0286     //! Sets reasonable dialog size based on main window size, that is 80% of its size.
0287     virtual void setReasonableDialogSize(QDialog *dialog) = 0;
0288 
0289 protected: // Q_SLOTS:
0290     virtual void slotObjectRenamed(const KexiPart::Item &item, const QString& oldName) = 0;
0291 
0292 };
0293 
0294 Q_DECLARE_OPERATORS_FOR_FLAGS(KexiMainWindowIface::SaveObjectOptions)
0295 
0296 #endif