Kexi API Documentation (2.0 alpha)

keximainwindowimpl_p.h

Go to the documentation of this file.
00001 /* This file is part of the KDE projec
00002    Copyright (C) 2003 Lucijan Busch <lucijan@kde.org>
00003    Copyright (C) 2003-2007 Jaroslaw Staniek <js@iidea.pl>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #ifdef KEXI_NO_PROCESS_EVENTS
00022 # define KEXI_NO_PENDING_DIALOGS
00023 #endif
00024 
00026 typedef QMap< int, QGuardedPtr<KexiDialogBase> > KexiDialogDict; 
00027 
00029 class KexiMainWindowImpl::Private
00030 {
00031 public:
00032     Private(KexiMainWindowImpl* w)
00033 //      : dialogs(401)
00034         : wnd(w)
00035         , m_openedCustomObjectsForItem(1019, true)
00036     {
00037         propEditor=0;
00038         propEditorToolWindow=0;
00039         propEditorTabWidget=0;
00040         userMode = false;
00041         nav=0;
00042         navToolWindow=0;
00043         prj = 0;
00044         curDialogGUIClient=0;
00045         curDialogViewGUIClient=0;
00046         closedDialogGUIClient=0;
00047         closedDialogViewGUIClient=0;
00048         nameDialog=0;
00049         curDialog=0;
00050         block_KMdiMainFrm_eventFilter=false;
00051         focus_before_popup=0;
00052 //      relationPart=0;
00053         privateIDCounter=0;
00054         action_view_nav=0;
00055         action_view_propeditor=0;
00056         action_view_mainarea=0;
00057         action_open_recent_projects_title_id = -1;
00058         action_open_recent_connections_title_id = -1;
00059         forceDialogClosing=false;
00060         insideCloseDialog=false;
00061 #ifndef KEXI_NO_PENDING_DIALOGS
00062         actionToExecuteWhenPendingJobsAreFinished = NoAction;
00063 #endif
00064 //      callSlotLastChildViewClosedAfterCloseDialog=false;
00065         createMenu=0;
00066         showImportantInfoOnStartup=true;
00067 //      disableErrorMessages=false;
00068 //      last_checked_mode=0;
00069         propEditorDockSeparatorPos=-1;
00070         navDockSeparatorPos=-1;
00071 //      navDockSeparatorPosWithAutoOpen=-1;
00072         wasAutoOpen = false;
00073         dialogExistedBeforeCloseProject = false;
00074 #ifndef KEXI_SHOW_UNIMPLEMENTED
00075         dummy_action = new KActionMenu("", wnd);
00076 #endif
00077         maximizeFirstOpenedChildFrm = false;
00078 #ifdef HAVE_KNEWSTUFF
00079         newStuff = 0;
00080 #endif
00081         mdiModeToSwitchAfterRestart = (KMdi::MdiMode)0;
00082         forceShowProjectNavigatorOnCreation = false;
00083         forceHideProjectNavigatorOnCreation = false;
00084         navWasVisibleBeforeProjectClosing = false;
00085         saveSettingsForShowProjectNavigator = true;
00086         m_openedCustomObjectsForItem.setAutoDelete(true);
00087     }
00088     ~Private() {
00089     }
00090 
00091 #ifndef KEXI_NO_PENDING_DIALOGS
00092 
00093     enum PendingJobType {
00094         NoJob = 0,
00095         DialogOpeningJob,
00096         DialogClosingJob
00097     };
00098 
00099     KexiDialogBase *openedDialogFor( const KexiPart::Item* item, PendingJobType &pendingType )
00100     {
00101         return openedDialogFor( item->identifier(), pendingType );
00102     }
00103 
00104     KexiDialogBase *openedDialogFor( int identifier, PendingJobType &pendingType )
00105     {
00106 //todo(threads)     QMutexLocker dialogsLocker( &dialogsMutex );
00107         QMap<int, PendingJobType>::ConstIterator it = pendingDialogs.find( identifier );
00108         if (it==pendingDialogs.constEnd())
00109             pendingType = NoJob;
00110         else
00111             pendingType = it.data();
00112         
00113         if (pendingType == DialogOpeningJob) {
00114             return 0;
00115         }
00116         return (KexiDialogBase*)dialogs[ identifier ];
00117     }
00118 #else
00119     KexiDialogBase *openedDialogFor( const KexiPart::Item* item )
00120     {
00121         return openedDialogFor( item->identifier() );
00122     }
00123 
00124     KexiDialogBase *openedDialogFor( int identifier )
00125     {
00126 //todo(threads)     QMutexLocker dialogsLocker( &dialogsMutex );
00127         return (KexiDialogBase*)dialogs[ identifier ];
00128     }
00129 #endif
00130 
00131     void insertDialog(KexiDialogBase *dlg) {
00132 //todo(threads)     QMutexLocker dialogsLocker( &dialogsMutex );
00133         dialogs.insert(dlg->id(), QGuardedPtr<KexiDialogBase>(dlg));
00134 #ifndef KEXI_NO_PENDING_DIALOGS
00135         pendingDialogs.remove(dlg->id());
00136 #endif
00137     }
00138 
00139 #ifndef KEXI_NO_PENDING_DIALOGS
00140     void addItemToPendingDialogs(const KexiPart::Item* item, PendingJobType jobType) {
00141 //todo(threads)     QMutexLocker dialogsLocker( &dialogsMutex );
00142         pendingDialogs.replace( item->identifier(), jobType );
00143     }
00144 
00145     bool pendingDialogsExist() {
00146         if (pendingDialogs.constBegin()!=pendingDialogs.constEnd())
00147             kdDebug() <<    pendingDialogs.constBegin().key() << " " << (int)pendingDialogs.constBegin().data() << endl;
00148 //todo(threads)     QMutexLocker dialogsLocker( &dialogsMutex );
00149         return !pendingDialogs.isEmpty();
00150     }
00151 #endif
00152 
00153     void updateDialogId(KexiDialogBase *dlg, int oldItemID) {
00154 //todo(threads)     QMutexLocker dialogsLocker( &dialogsMutex );
00155         dialogs.remove(oldItemID);
00156 #ifndef KEXI_NO_PENDING_DIALOGS
00157         pendingDialogs.remove(oldItemID);
00158 #endif
00159         dialogs.insert(dlg->id(), QGuardedPtr<KexiDialogBase>(dlg));
00160     }
00161 
00162     void removeDialog(int identifier) {
00163 //todo(threads)     QMutexLocker dialogsLocker( &dialogsMutex );
00164         dialogs.remove(identifier);
00165     }
00166 
00167 #ifndef KEXI_NO_PENDING_DIALOGS
00168     void removePendingDialog(int identifier) {
00169 //todo(threads)     QMutexLocker dialogsLocker( &dialogsMutex );
00170         pendingDialogs.remove(identifier);
00171     }
00172 #endif
00173 
00174     uint openedDialogsCount() {
00175 //todo(threads)     QMutexLocker dialogsLocker( &dialogsMutex );
00176         return dialogs.count();
00177     }
00178 
00180     void clearDialogs() {
00181 //todo(threads)     QMutexLocker dialogsLocker( &dialogsMutex );
00182         dialogs.clear();
00183 #ifndef KEXI_NO_PENDING_DIALOGS
00184         pendingDialogs.clear();
00185 #endif
00186     }
00187 
00189     void toggleLastCheckedMode()
00190     {
00191         if (curDialog.isNull())
00192             return;
00193         KRadioAction *ra = actions_for_view_modes[ curDialog->currentViewMode() ];
00194         if (ra)
00195             ra->setChecked(true);
00196 //      if (!last_checked_mode)
00197 //          return;
00198 //      last_checked_mode->setChecked(true);
00199     }
00200 
00201 /*
00202 void updatePropEditorDockWidthInfo() {
00203         if (propEditor) {
00204             KDockWidget *dw = (KDockWidget *)propEditor->parentWidget();
00205 #if defined(KDOCKWIDGET_P)
00206             KDockSplitter *ds = (KDockSplitter *)dw->parentWidget();
00207             if (ds) {
00208                 propEditorDockSeparatorPos = ds->separatorPosInPercent();*/
00209 /*              if (propEditorDockSeparatorPos<=0) {
00210                         config->setGroup("MainWindow");
00211                         propEditorDockSeparatorPos = config->readNumEntry("RightDockPosition", 80);
00212                         ds->setSeparatorPos(propEditorDockSeparatorPos, true);
00213                 }*/
00214             /*}
00215 #endif
00216         }
00217     }*/
00218 
00219     void showStartProcessMsg(const QStringList& args)
00220     {
00221         wnd->showErrorMessage(i18n("Could not start %1 application.").arg(KEXI_APP_NAME),
00222             i18n("Command \"%1\" failed.").arg(args.join(" ")));
00223     }
00224 
00225     void hideMenuItem(const QString& menuName, const QString& itemText, bool alsoSeparator)
00226     {
00227         QPopupMenu *pm = popups[menuName.ascii()];
00228         if (!pm)
00229             return;
00230         uint i=0;
00231         const uint c = pm->count();
00232         for (;i<c;i++) {
00233             kdDebug() << pm->text( pm->idAt(i) ) <<endl;
00234             if (pm->text( pm->idAt(i) ).lower().stripWhiteSpace()==itemText.lower().stripWhiteSpace())
00235                 break;
00236         }
00237         if (i<c) {
00238             pm->setItemVisible( pm->idAt(i), false );
00239             if (alsoSeparator)
00240                 pm->setItemVisible( pm->idAt(i+1), false ); //also separator
00241         }
00242     }
00243     
00244     void disableMenuItem(const QString& menuName, const QString& itemText)
00245     {
00246         QPopupMenu *pm = popups[menuName.ascii()];
00247         if (!pm)
00248             return;
00249         uint i=0;
00250         const uint c = pm->count();
00251         for (;i<c;i++) {
00252             if (pm->text( pm->idAt(i) ).lower().stripWhiteSpace()==itemText.lower().stripWhiteSpace())
00253                 break;
00254         }
00255         if (i<c)
00256             pm->setItemEnabled( pm->idAt(i), false );
00257     }
00258 
00259     void updatePropEditorVisibility(int viewMode)
00260     {
00261         if (propEditorToolWindow) {
00262             if (viewMode==0 || viewMode==Kexi::DataViewMode) {
00263 #ifdef PROPEDITOR_VISIBILITY_CHANGES
00264                 wnd->makeDockInvisible( wnd->manager()->findWidgetParentDock(propEditor) );
00265 //              propEditorToolWindow->hide();
00266 #endif
00267             } else {
00268                 //propEditorToolWindow->show();
00269                 QWidget *origFocusWidget = qApp->focusWidget();
00270                 wnd->makeWidgetDockVisible(propEditorTabWidget);
00271                 if (origFocusWidget)
00272                     origFocusWidget->setFocus();
00273 /*moved
00274 #if defined(KDOCKWIDGET_P)
00275                 KDockWidget *dw = (KDockWidget *)propEditor->parentWidget();
00276                 KDockSplitter *ds = (KDockSplitter *)dw->parentWidget();
00277                 ds->setSeparatorPosInPercent(config->readNumEntry("RightDockPosition", 80));//%
00278 #endif*/
00279             }
00280         }
00281     }
00282 
00283     void restoreNavigatorWidth()
00284     {
00285 #if defined(KDOCKWIDGET_P)
00286             if (wnd->mdiMode()==KMdi::ChildframeMode || wnd->mdiMode()==KMdi::TabPageMode) {
00287                 KDockWidget *dw = (KDockWidget *)nav->parentWidget();
00288                 KDockSplitter *ds = (KDockSplitter *)dw->parentWidget();
00289 //              ds->setKeepSize(true);
00290 
00291                 config->setGroup("MainWindow");
00292 # if KDE_VERSION >= KDE_MAKE_VERSION(3,4,0)
00293 
00294                 if (wasAutoOpen) //(dw2->isVisible())
00295 //              ds->setSeparatorPosInPercent( 100 * nav->width() / wnd->width() );
00296                     ds->setSeparatorPosInPercent(
00297                         QMAX(QMAX( config->readNumEntry("LeftDockPositionWithAutoOpen",20),
00298                         config->readNumEntry("LeftDockPosition",20)),20)
00299                     );
00300                 else
00301                     ds->setSeparatorPosInPercent(
00302                     QMAX(20, config->readNumEntry("LeftDockPosition", 20/* % */)));
00303 
00304     //          dw->resize( d->config->readNumEntry("LeftDockPosition", 115/* % */), dw->height() );
00305 # else
00306                 //there were problems on KDE < 3.4
00307                 ds->setSeparatorPosInPercent( 20 );
00308 # endif
00309                 //if (!wasAutoOpen) //(dw2->isVisible())
00310 //                  ds->setSeparatorPos( ds->separatorPos(), true );
00311             }
00312 #endif
00313     }
00314 
00315     template<class type>
00316     type *openedCustomObjectsForItem(KexiPart::Item* item, const char* name)
00317     {
00318         if (!item || !name) {
00319             kdWarning() << 
00320                 "KexiMainWindowImpl::Private::openedCustomObjectsForItem(): !item || !name" << endl;
00321             return 0;
00322         }
00323         QString key( QString::number(item->identifier()) + name );
00324         return dynamic_cast<type*>( m_openedCustomObjectsForItem.find( key.latin1() ) );
00325     }
00326 
00327     void addOpenedCustomObjectForItem(KexiPart::Item* item, QObject* object, const char* name)
00328     {
00329         QString key = QString::number(item->identifier()) + name;
00330         m_openedCustomObjectsForItem.insert( key.latin1(), object );
00331     }
00332 
00333         KexiMainWindowImpl *wnd;
00334         KexiStatusBar *statusBar;
00335         KexiProject *prj;
00336         KConfig *config;
00337 #ifndef KEXI_NO_CTXT_HELP
00338         KexiContextHelp *ctxHelp;
00339 #endif
00340         KexiBrowser *nav;
00341         KTabWidget *propEditorTabWidget;
00344         QGuardedPtr<KexiPart::Part> partForPreviouslySetupPropertyPanelTabs;
00345         QMap<KexiPart::Part*, int> recentlySelectedPropertyPanelPages;
00346         QGuardedPtr<KexiPropertyEditorView> propEditor;
00347         QGuardedPtr<KoProperty::Set> propBuffer;
00348 
00349         KXMLGUIClient *curDialogGUIClient, *curDialogViewGUIClient,
00350             *closedDialogGUIClient, *closedDialogViewGUIClient;
00351         QGuardedPtr<KexiDialogBase> curDialog;
00352 
00353         KexiNameDialog *nameDialog;
00354 
00355         QTimer timer; //helper timer
00356 //      QSignalMapper *actionMapper;
00357 
00358         QAsciiDict<QPopupMenu> popups; //list of menu popups
00359         QPopupMenu *createMenu;
00360 
00361         QString origAppCaption; //<! original application's caption (without project name)
00362         QString appCaptionPrefix; //<! application's caption prefix - prj name (if opened), else: null
00363 
00364 #ifndef KEXI_SHOW_UNIMPLEMENTED
00365         KActionMenu *dummy_action;
00366 #endif
00367 
00369         KAction *action_save, *action_save_as, *action_close,
00370             *action_project_properties, *action_open_recent_more,
00371             *action_project_relations, *action_project_import_data_table,
00372             *action_project_export_data_table,
00373             *action_project_print, *action_project_print_preview, 
00374             *action_project_print_setup;
00375 //      KRecentFilesAction *action_open_recent;
00376         KActionMenu *action_open_recent, *action_show_other;
00377 //      int action_open_recent_more_id;
00378         int action_open_recent_projects_title_id,
00379             action_open_recent_connections_title_id;
00380 
00382         KAction *action_edit_delete, *action_edit_delete_row,
00383             *action_edit_cut, *action_edit_copy, *action_edit_paste,
00384             *action_edit_select_all,
00385             *action_edit_undo, *action_edit_redo,
00386             *action_edit_insert_empty_row,
00387             *action_edit_edititem, *action_edit_clear_table,
00388             *action_edit_paste_special_data_table,
00389             *action_edit_copy_special_data_table;
00390 
00392         KAction *action_view_nav, *action_view_propeditor, *action_view_mainarea;
00393         KRadioAction *action_view_data_mode, *action_view_design_mode, *action_view_text_mode;
00394         QIntDict<KRadioAction> actions_for_view_modes;
00395 //      KRadioAction *last_checked_mode;
00396 #ifndef KEXI_NO_CTXT_HELP
00397         KToggleAction *action_show_helper;
00398 #endif
00399 
00400         KAction *action_data_save_row;
00401         KAction *action_data_cancel_row_changes;
00402         KAction *action_data_execute;
00403 
00405         KAction *action_format_font;
00406 
00408         KAction *action_tools_data_migration, *action_tools_compact_database;
00409         KActionMenu *action_tools_scripts;
00410 
00412         KAction *action_window_next, *action_window_previous;
00413 
00415         KAction *action_configure;
00416 
00418         KMdiToolViewAccessor* navToolWindow;
00419         KMdiToolViewAccessor* propEditorToolWindow;
00420 
00421         QGuardedPtr<QWidget> focus_before_popup;
00422 //      KexiRelationPart *relationPart;
00423 
00424         int privateIDCounter; 
00425 
00426         bool block_KMdiMainFrm_eventFilter : 1;
00427 
00431         bool forceDialogClosing : 1;
00432 
00435         bool insideCloseDialog : 1;
00436 
00437 #ifndef KEXI_NO_PENDING_DIALOGS
00438 
00439         enum ActionToExecuteWhenPendingJobsAreFinished {
00440             NoAction,
00441             QuitAction,
00442             CloseProjectAction
00443         };
00444         ActionToExecuteWhenPendingJobsAreFinished actionToExecuteWhenPendingJobsAreFinished;
00445 
00446         void executeActionWhenPendingJobsAreFinished() {
00447             ActionToExecuteWhenPendingJobsAreFinished a = actionToExecuteWhenPendingJobsAreFinished;
00448             actionToExecuteWhenPendingJobsAreFinished = NoAction;
00449             switch (a) {
00450                 case QuitAction: 
00451                     qApp->quit();
00452                     break;
00453                 case CloseProjectAction:
00454                     wnd->closeProject();
00455                     break;
00456                 default:;
00457             }
00458         }
00459 #endif
00460 
00462         QPtrList<KexiDialogBase> windowsToClose;
00463 
00465         QIntDict<KexiDialogBase> pageSetupDialogs;
00466 
00470         QMap<int, int> pageSetupDialogItemID2dataItemID_map;
00471 
00474         bool showImportantInfoOnStartup : 1;
00475 
00476 //      //! Used sometimes to block showErrorMessage()
00477 //      bool disableErrorMessages : 1;
00478 
00480         bool userMode : 1;
00481 
00483         bool isProjectNavigatorVisible : 1;
00484 
00486         bool maximizeFirstOpenedChildFrm : 1;
00487 
00490         bool forceShowProjectNavigatorOnCreation : 1;
00491         bool forceHideProjectNavigatorOnCreation : 1;
00492 
00493         bool navWasVisibleBeforeProjectClosing : 1;
00494         bool saveSettingsForShowProjectNavigator : 1;
00495 #ifdef HAVE_KNEWSTUFF
00496         KexiNewStuff  *newStuff;
00497 #endif
00498 
00500         QAsciiDict<QObject> m_openedCustomObjectsForItem;
00501 
00502     int propEditorDockSeparatorPos, navDockSeparatorPos;
00503 //  int navDockSeparatorPosWithAutoOpen;
00504     bool wasAutoOpen;
00505     bool dialogExistedBeforeCloseProject;
00506 
00507     KMdi::MdiMode mdiModeToSwitchAfterRestart;
00508 
00509 protected:
00511     KexiDialogDict dialogs;
00512 #ifndef KEXI_NO_PROCESS_EVENTS
00513     QMap<int, PendingJobType> pendingDialogs; 
00514 //todo(threads) QMutex dialogsMutex; //!< used for locking dialogs and pendingDialogs dicts
00515 #endif
00516 };
KDE Logo
This file is part of the documentation for Kexi 2.0 alpha.
Documentation copyright © 2002-2007 the Kexi Team.
Generated on Tue Apr 1 20:48:25 2008 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003