Source Code (Use browser search to find items of interest.)

Class Index

katabase'KformEditorShell (./koffice/katabase/kformeditor/kformeditor_shell.h:29)

class KformEditorShell : public KoMainWindow
{
  Q_OBJECT

public:
  KformEditorShell();
  ~KformEditorShell();
  virtual void cleanUp();
  void setDocument( KformEditorDoc* _doc );
  virtual bool newDocument();
  virtual bool openDocument( const char *  _filename );
  virtual bool saveDocument();
  virtual bool closeDocument();
  virtual bool closeAllDocuments();

protected slots:
  void slotFileNew();
  void slotFileOpen();
  void slotFileSave();
  void slotFileSaveAs();
  void slotFilePrint();
  void slotFileClose();
  void slotFileQuit();

protected:
  virtual KOffice::Document_ptr document();
  virtual KOffice::View_ptr view();
  virtual bool printDlg();
  virtual void helpAbout();
  virtual int documentCount();
  bool isModified();
  bool requestClose();
  void releaseDocument();

  KformEditorDoc* m_pDoc;
  KformEditorView* m_pView;

  static QList<KformEditorShell>* s_lstShells;
};

katabase'KformEditorShell::KformEditorShell() (./koffice/katabase/kformeditor/kformeditor_shell.cc:42)

KformEditorShell::KformEditorShell()
{
  m_pDoc = 0L;
  m_pView = 0L;

  if ( s_lstShells == 0L )
    s_lstShells = new QList<KformEditorShell>;

  s_lstShells->append( this );
}


katabase'KformEditorShell::~KformEditorShell() (./koffice/katabase/kformeditor/kformeditor_shell.cc:53)

KformEditorShell::~KformEditorShell()
{
  kdebug( KDEBUG_INFO, 0, "KformEditorShell::~KformEditorShell()" );

  cleanUp();

  s_lstShells->removeRef( this );
}


katabase'KformEditorShell::isModified() (./koffice/katabase/kformeditor/kformeditor_shell.cc:62)

bool KformEditorShell::isModified()
{
  if ( m_pDoc )
    return (bool)m_pDoc->isModified();

  return false;
}


katabase'KformEditorShell::requestClose() (./koffice/katabase/kformeditor/kformeditor_shell.cc:70)

bool KformEditorShell::requestClose()
{
  int res = QMessageBox::warning( 0L, i18n("Warning"), i18n("The document has been modified\nDo you want to save it ?" ),
				  i18n("Yes"), i18n("No"), i18n("Cancel") );

  if ( res == 0 )
    return saveDocument();

  if ( res == 1 )
    return true;

  return false;
}


katabase'KformEditorShell::cleanUp() (./koffice/katabase/kformeditor/kformeditor_shell.cc:84)

void KformEditorShell::cleanUp()
{
  releaseDocument();

  KoMainWindow::cleanUp();
}


katabase'KformEditorShell::setDocument() (./koffice/katabase/kformeditor/kformeditor_shell.cc:91)

void KformEditorShell::setDocument( KformEditorDoc *_doc )
{
  if ( m_pDoc )
    releaseDocument();

  m_pDoc = _doc;
  m_pDoc->_ref();
  m_pView = _doc->createFormView( frame() );
  m_pView->incRef();
  m_pView->setMode( KOffice::View::RootMode );
  m_pView->setMainWindow( interface() );

  setRootPart( m_pView );
  interface()->setActivePart( m_pView->id() );

  if( m_pFileMenu )
  {
    m_pFileMenu->setItemEnabled( m_idMenuFile_Save, true );
    m_pFileMenu->setItemEnabled( m_idMenuFile_SaveAs, true );
    m_pFileMenu->setItemEnabled( m_idMenuFile_Close, true );
    m_pFileMenu->setItemEnabled( m_idMenuFile_Print, true );
  }

  opToolBar()->setItemEnabled( TOOLBAR_PRINT, true );
  opToolBar()->setItemEnabled( TOOLBAR_SAVE, true );
}


katabase'KformEditorShell::newDocument() (./koffice/katabase/kformeditor/kformeditor_shell.cc:118)

bool KformEditorShell::newDocument()
{
  if ( m_pDoc )
  {
    KformEditorShell *s = new KformEditorShell();
    s->show();
    s->newDocument();
    return true;
  }

  m_pDoc = new KformEditorDoc;
  if ( !m_pDoc->initDoc() )
  {
    releaseDocument();
    kdebug( KDEBUG_FATAL, 0, "ERROR: Could not initialize document" );
    return false;
  }

  m_pView = m_pDoc->createFormView( frame() );
  m_pView->incRef();
  m_pView->setMode( KOffice::View::RootMode );
  kdebug( KDEBUG_INFO, 0, "*1) VIEW void KOMBase::refcnt() = %li", m_pView->_refcnt() );
  m_pView->setMainWindow( interface() );

  setRootPart( m_pView );
  interface()->setActivePart( m_pView->id() );

  if( m_pFileMenu )
  {
    m_pFileMenu->setItemEnabled( m_idMenuFile_Save, true );
    m_pFileMenu->setItemEnabled( m_idMenuFile_SaveAs, true );
    m_pFileMenu->setItemEnabled( m_idMenuFile_Close, true );
    m_pFileMenu->setItemEnabled( m_idMenuFile_Print, true );
  }

  opToolBar()->setItemEnabled( TOOLBAR_PRINT, true );
  opToolBar()->setItemEnabled( TOOLBAR_SAVE, true );

  kdebug( KDEBUG_INFO, 0, "*2) VIEW void KOMBase::refcnt() = %li", m_pView->_refcnt() );

  return true;
}


katabase'KformEditorShell::openDocument() (./koffice/katabase/kformeditor/kformeditor_shell.cc:161)

bool KformEditorShell::openDocument( const char *_url )
{
  if ( m_pDoc && m_pDoc->isEmpty() )
    releaseDocument();
  else if ( m_pDoc && !m_pDoc->isEmpty() )
  {
    KformEditorShell *s = new KformEditorShell();
    s->show();
    return s->openDocument( _url );
  }

  kdebug( KDEBUG_INFO, 0, "Creating new document" );

  m_pDoc = new KformEditorDoc;
  if ( !m_pDoc->loadFromURL( _url ) )
  {
    kdebug( KDEBUG_INFO, 0, "MK: nicht load from URL" );
    return false;
  }
  m_pView = m_pDoc->createFormView( frame() );
  m_pView->incRef();
  m_pView->setMode( KOffice::View::RootMode );
  m_pView->setMainWindow( interface() );

  setRootPart( m_pView );
  interface()->setActivePart( m_pView->id() );

  if ( m_pFileMenu )
  {
    m_pFileMenu->setItemEnabled( m_idMenuFile_SaveAs, false );
    m_pFileMenu->setItemEnabled( m_idMenuFile_Save, false );
    m_pFileMenu->setItemEnabled( m_idMenuFile_Close, true );
    m_pFileMenu->setItemEnabled( m_idMenuFile_Print, false );
  }

  opToolBar()->setItemEnabled( TOOLBAR_PRINT, false );
  opToolBar()->setItemEnabled( TOOLBAR_SAVE, false );

  return true;
}


katabase'KformEditorShell::saveDocument() (./koffice/katabase/kformeditor/kformeditor_shell.cc:202)

bool KformEditorShell::saveDocument()
{
  ASSERT( m_pDoc != 0L );
  return KoMainWindow::saveDocument( "application/x-kformeditor", "*.kfe", "KFormEditor" );
  // choose your suffix :)  (David)
}


katabase'KformEditorShell::printDlg() (./koffice/katabase/kformeditor/kformeditor_shell.cc:209)

bool KformEditorShell::printDlg()
{
  ASSERT( m_pView != 0L );

  return m_pView->printDlg();
}


katabase'KformEditorShell::helpAbout() (./koffice/katabase/kformeditor/kformeditor_shell.cc:216)

void KformEditorShell::helpAbout()
{
  // KoAboutDia::about( KoAboutDia::KformEditor, "0.0.2" );
}


katabase'KformEditorShell::closeDocument() (./koffice/katabase/kformeditor/kformeditor_shell.cc:221)

bool KformEditorShell::closeDocument()
{
  if ( isModified() )
  {
    if ( !requestClose() )
      return false;
  }

  return true;
}


katabase'KformEditorShell::closeAllDocuments() (./koffice/katabase/kformeditor/kformeditor_shell.cc:232)

bool KformEditorShell::closeAllDocuments()
{
  KformEditorShell* s;
  for( s = s_lstShells->first(); s != 0L; s = s_lstShells->next() )
  {
    if ( s->isModified() )
    {
      if ( !s->requestClose() )
	return false;
    }
  }

  return true;
}


katabase'KformEditorShell::documentCount() (./koffice/katabase/kformeditor/kformeditor_shell.cc:247)

int KformEditorShell::documentCount()
{
  return s_lstShells->count();
}


katabase'KformEditorShell::releaseDocument() (./koffice/katabase/kformeditor/kformeditor_shell.cc:252)

void KformEditorShell::releaseDocument()
{
  int views = 0;
  if ( m_pDoc )
    views = m_pDoc->viewCount();

  setRootPart( (long unsigned int)(OpenParts::Id)0 );

  interface()->setActivePart( 0 );

  if ( m_pView )
    m_pView->decRef();

  /* if ( m_pView )
    m_pView->cleanUp(); */

  if ( m_pDoc && views <= 1 )
    m_pDoc->cleanUp();
  // if ( m_pView )
  // CORBA::release( m_pView );
  if ( m_pDoc )
    CORBA::release( m_pDoc );
  m_pView = 0L;
  m_pDoc = 0L;

  if ( m_pFileMenu )
  {
    m_pFileMenu->setItemEnabled( m_idMenuFile_SaveAs, false );
    m_pFileMenu->setItemEnabled( m_idMenuFile_Save, false );
    m_pFileMenu->setItemEnabled( m_idMenuFile_Close, false );
    m_pFileMenu->setItemEnabled( m_idMenuFile_Print, false );
  }

  opToolBar()->setItemEnabled( TOOLBAR_PRINT, false );
  opToolBar()->setItemEnabled( TOOLBAR_SAVE, false );
}


katabase'KformEditorShell::slotFileNew() (./koffice/katabase/kformeditor/kformeditor_shell.cc:289)

void KformEditorShell::slotFileNew()
{
  if ( !newDocument() )
    QMessageBox::critical( this, i18n("KformEditor Error"), i18n("Could not create new document"), i18n("OK") );
}


katabase'KformEditorShell::slotFileOpen() (./koffice/katabase/kformeditor/kformeditor_shell.cc:295)

void KformEditorShell::slotFileOpen()
{
  QString file = KFileDialog::getOpenFileName( getenv( "HOME" ) );

  if ( file.isNull() )
    return;

  if ( openDocument( file  ) )
  {
    QString tmp;
    tmp.sprintf( i18n( "Could not open\n%s" ), file.data() );
    QMessageBox::critical( this, i18n( "IO Error" ), tmp, i18n( "OK" ) );
  }
}


katabase'KformEditorShell::slotFileSave() (./koffice/katabase/kformeditor/kformeditor_shell.cc:310)

void KformEditorShell::slotFileSave()
{
  ASSERT( m_pDoc != 0L );
  (void) saveDocument();
}


katabase'KformEditorShell::slotFileSaveAs() (./koffice/katabase/kformeditor/kformeditor_shell.cc:316)

void KformEditorShell::slotFileSaveAs()
{
  QString _url = m_pDoc->url();
  m_pDoc->setURL( "" );

  if ( !saveDocument() )
    m_pDoc->setURL( _url );
}


katabase'KformEditorShell::slotFileClose() (./koffice/katabase/kformeditor/kformeditor_shell.cc:325)

void KformEditorShell::slotFileClose()
{
  if ( isModified() )
    if ( !requestClose() )
      return;

  releaseDocument();
}


katabase'KformEditorShell::slotFilePrint() (./koffice/katabase/kformeditor/kformeditor_shell.cc:334)

void KformEditorShell::slotFilePrint()
{
  ASSERT( m_pView );

  (void)m_pView->printDlg();
}


katabase'KformEditorShell::slotFileQuit() (./koffice/katabase/kformeditor/kformeditor_shell.cc:341)

void KformEditorShell::slotFileQuit()
{
  kdebug( KDEBUG_INFO, 0, "EXIT 1" );

  if ( !closeAllDocuments() )
    return;

  kdebug( KDEBUG_INFO, 0, "EXIT 2" );

  delete this;
  kapp->exit();
}

KOffice::Document_ptr KformEditorShell::document()
{
  return KOffice::Document::_duplicate( m_pDoc );
}

KOffice::View_ptr KformEditorShell::view()
{
  return KOffice::View::_duplicate( m_pView );
}