00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <qvbox.h>
00021 #include <qlabel.h>
00022 #include <qheader.h>
00023
00024 #include <klocale.h>
00025 #include <kpushbutton.h>
00026 #include <klistbox.h>
00027 #include <klistview.h>
00028 #include <kstdguiitem.h>
00029
00030 #include "ksavealldialog.h"
00031
00032 namespace
00033 {
00034
00035 class CheckURL : public QCheckListItem
00036 {
00037 public:
00038 CheckURL( QListView * lv, KURL const & url )
00039 : QCheckListItem( lv, url.path(), QCheckListItem::CheckBox),
00040 _url( url )
00041 {}
00042
00043 KURL const & url() const { return _url; }
00044
00045 private:
00046 KURL _url;
00047 };
00048
00049 }
00050
00051
00052 KSaveSelectDialog::KSaveSelectDialog( KURL::List const & filelist, KURL::List const & ignorelist, QWidget * parent ) :
00053 KDialogBase( parent, "SaveAllDialog", true, i18n("Save Modified Files?"),
00054 Ok | User1 | Close )
00055 {
00056 QVBox *top = makeVBoxMainWidget();
00057
00058 (void)new QLabel( i18n("The following files have been modified. Save them?"), top );
00059
00060 _listview = new KListView( top );
00061 _listview->addColumn( "" );
00062 _listview->header()->hide();
00063 _listview->setResizeMode( QListView::LastColumn );
00064
00065 setButtonOKText( i18n("Save &Selected"), i18n("Saves all selected files") );
00066 setButtonText( User1, i18n("Save &None") );
00067 setButtonText( Close, KStdGuiItem::cancel().text() );
00068 setButtonTip( User1, i18n("Lose all modifications") );
00069 setButtonTip( Close, i18n("Cancels the action") );
00070
00071 KURL::List::ConstIterator it = filelist.begin();
00072 while ( it != filelist.end() )
00073 {
00074 if ( !ignorelist.contains( *it ) )
00075 {
00076 QCheckListItem * x = new CheckURL( _listview, *it );
00077 x->setOn( true );
00078 }
00079 ++it;
00080 }
00081
00082 connect( this, SIGNAL(closeClicked()), this, SLOT(cancel()) );
00083 connect( this, SIGNAL(okClicked()), this, SLOT(save()) );
00084 connect( this, SIGNAL(user1Clicked()), this, SLOT(saveNone()) );
00085 }
00086
00087 KSaveSelectDialog::~KSaveSelectDialog() {}
00088
00089 void KSaveSelectDialog::saveNone( )
00090 {
00091
00092 CheckURL * item = static_cast<CheckURL*>( _listview->firstChild() );
00093 while ( item )
00094 {
00095 item->setOn( false );
00096 item = static_cast<CheckURL*>( item->nextSibling() );
00097 }
00098
00099 QDialog::accept();
00100 }
00101
00102 void KSaveSelectDialog::save( )
00103 {
00104 QDialog::accept();
00105 }
00106
00107 void KSaveSelectDialog::cancel( )
00108 {
00109 QDialog::reject();
00110 }
00111
00112 KURL::List KSaveSelectDialog::filesToSave( )
00113 {
00114 KURL::List filelist;
00115 CheckURL const * item = static_cast<CheckURL*>( _listview->firstChild() );
00116 while ( item )
00117 {
00118 if ( item->isOn() )
00119 {
00120 filelist << item->url();
00121 }
00122 item = static_cast<CheckURL*>( item->nextSibling() );
00123 }
00124 return filelist;
00125 }
00126
00127 KURL::List KSaveSelectDialog::filesNotToSave( )
00128 {
00129 KURL::List filelist;
00130 CheckURL const * item = static_cast<CheckURL*>( _listview->firstChild() );
00131 while ( item )
00132 {
00133 if ( ! item->isOn() )
00134 {
00135 filelist << item->url();
00136 }
00137 item = static_cast<CheckURL*>( item->nextSibling() );
00138 }
00139 return filelist;
00140 }
00141
00142
00143 KSaveAllDialog::KSaveAllDialog( const QStringList& filenames, QWidget* parent ) :
00144 KDialogBase( parent, "SaveAllDialog", true, i18n("Save Modified Files?"),
00145 Ok | User1 | Close )
00146 {
00147 m_result = Cancel;
00148
00149 QVBox *top = makeVBoxMainWidget();
00150
00151 (void)new QLabel( i18n("The following files have been modified. Save them?"), top );
00152 KListBox* lb = new KListBox( top );
00153 lb->setMinimumHeight( lb->fontMetrics().height() * 5 );
00154 lb->insertStringList( filenames );
00155
00156 setButtonOKText( i18n("Save &All"), i18n("Saves all modified files") );
00157 setButtonText( User1, i18n("Save &None") );
00158 setButtonText( Close, KStdGuiItem::cancel().text() );
00159 setButtonTip( User1, i18n("Lose all modifications") );
00160 setButtonTip( Close, i18n("Cancels the action") );
00161
00162 connect( this, SIGNAL(closeClicked()), this, SLOT(cancel()) );
00163 connect( this, SIGNAL(okClicked()), this, SLOT(saveAll()) );
00164 connect( this, SIGNAL(user1Clicked()), this, SLOT(revert()) );
00165 }
00166
00167 KSaveAllDialog::~KSaveAllDialog()
00168 {
00169 }
00170
00171 void KSaveAllDialog::revert()
00172 {
00173 m_result = Revert;
00174 QDialog::accept();
00175 }
00176
00177 void KSaveAllDialog::saveAll()
00178 {
00179 m_result = SaveAll;
00180 QDialog::accept();
00181 }
00182
00183 void KSaveAllDialog::cancel()
00184 {
00185 m_result = Cancel;
00186 QDialog::reject();
00187 }
00188
00189 #include "ksavealldialog.moc"