My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
savedialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2006 by Gopala Krishna A <krishna.ggk@gmail.com> *
3  * Copyright (C) 2007 Stefan Jahn <stefan@lkcc.org> *
4  * *
5  * This is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2, or (at your option) *
8  * any later version. *
9  * *
10  * This software is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this package; see the file COPYING. If not, write to *
17  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, *
18  * Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 
21 #include "savedialog.h"
22 #include "qucs.h"
23 #include "qucsdoc.h"
24 
25 #include <qvariant.h>
26 #include <qlabel.h>
27 #include <qheader.h>
28 #include <qlistview.h>
29 #include <qpushbutton.h>
30 #include <qlayout.h>
31 #include <qtooltip.h>
32 #include <qwhatsthis.h>
33 
34 SaveDialog::SaveDialog( QWidget* parent, const char* name, bool modal, WFlags fl )
35  : QDialog( parent, name, modal, fl ),unsavedDocs()
36 {
37  if ( !name )
38  setName( "SaveDialog" );
39  app = 0l;
40  initDialog();
41 }
42 
44 {
45 }
46 
48 {
49  app = a;
50 }
51 
52 void SaveDialog::initDialog()
53 {
54  setSizeGripEnabled( FALSE );
55  SaveDialogLayout = new QVBoxLayout( this, 11, 6, "SaveDialogLayout");
56 
57  label = new QLabel( this, "label" );
58  SaveDialogLayout->addWidget( label );
59 
60  filesView = new QListView( this, "filesView" );
61  filesView->addColumn( tr( "Modified Files" ) );
62  filesView->header()->setResizeEnabled( FALSE, filesView->header()->count() - 1 );
63  filesView->setItemMargin( 1 );
64  filesView->setResizeMode( QListView::AllColumns );
65  SaveDialogLayout->addWidget( filesView );
66 
67  buttonsLayout = new QHBoxLayout( 0, 0, 6, "buttonsLayout");
68 
69  abortClosingButton = new QPushButton( this, "abortClosingButton" );
70  buttonsLayout->addWidget( abortClosingButton );
71  spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
72  buttonsLayout->addItem( spacer );
73 
74  dontSaveButton = new QPushButton( this, "dontSaveButton" );
75  buttonsLayout->addWidget( dontSaveButton );
76 
77  saveSelectedButton = new QPushButton( this, "saveSelectedButton" );
78  saveSelectedButton->setDefault(true);
79  buttonsLayout->addWidget( saveSelectedButton );
80  SaveDialogLayout->addLayout( buttonsLayout );
82  resize( QSize(500, 300).expandedTo(minimumSizeHint()) );
83  clearWState( WState_Polished );
84 
85  connect(abortClosingButton,SIGNAL(clicked()),this,SLOT(reject()));
86  connect(dontSaveButton,SIGNAL(clicked()),this,SLOT(dontSaveClicked()));
87  connect(saveSelectedButton,SIGNAL(clicked()),this,SLOT(saveSelectedClicked()));
88 }
89 
91 {
92  QString text = (doc->DocName).isEmpty() ? tr("Untitled") : doc->DocName;
93  QCheckListItem *item = new QCheckListItem(filesView,
94  text,
95  QCheckListItem::CheckBox );
96  item->setOn( true );
97  unsavedDocs.insert( doc, item );
98 }
99 
101 {
102  setCaption( tr( "Save the modified files" ) );
103  label->setText( tr( "Select files to be saved" ) );
104  filesView->header()->setLabel( 0, tr( "Modified Files" ) );
105  abortClosingButton->setText( tr( "Abort Closing" ) );
106  dontSaveButton->setText( tr( "Don't Save" ) );
107  saveSelectedButton->setText( tr( "Save Selected" ) );
108 }
109 
111 {
112  done(DontSave);
113 }
114 
116 {
117  QPtrList<QucsDoc> unsavables;
118  QMap<QucsDoc*,QCheckListItem*>::iterator it(unsavedDocs.begin());
119  for ( ; it != unsavedDocs.end(); ++it)
120  {
121  if ( it.data()->isOn() )
122  {
123  QucsDoc *doc = static_cast<QucsDoc*>(it.key());
124  if(app->saveFile(doc) == false)
125  unsavables.append(doc);
126  else
127  unsavedDocs.remove(it);
128  }
129  }
130  if(unsavables.isEmpty())
131  done(SaveSelected);
132 }
133 
135 {
136  done(AbortClosing);
137 }
138 
140 {
141  return unsavedDocs.isEmpty();
142 }