-rw-r--r-- | korganizer/kofilterview.cpp | 28 | ||||
-rw-r--r-- | korganizer/kofilterview.h | 32 |
2 files changed, 49 insertions, 11 deletions
diff --git a/korganizer/kofilterview.cpp b/korganizer/kofilterview.cpp index ce2880a..9709324 100644 --- a/korganizer/kofilterview.cpp +++ b/korganizer/kofilterview.cpp @@ -52,382 +52,390 @@ KOFilterView::KOFilterView(QPtrList<CalFilter> *filterList,QWidget* parent, connect(mSelectionCombo,SIGNAL(activated(int)),SIGNAL(filterChanged())); connect(mEnabledCheck,SIGNAL(clicked()),SIGNAL(filterChanged())); connect(mEditButton,SIGNAL(clicked()),SIGNAL(editFilters())); } KOFilterView::~KOFilterView() { // no need to delete child widgets, Qt does it all for us } bool KOFilterView::filtersEnabled() { return mEnabledCheck->isChecked(); } void KOFilterView::setFiltersEnabled(bool set) { mEnabledCheck->setChecked(set); emit filterChanged(); } void KOFilterView::updateFilters() { mSelectionCombo->clear(); CalFilter *filter = mFilters->first(); while(filter) { mSelectionCombo->insertItem(filter->name()); filter = mFilters->next(); } } CalFilter *KOFilterView::selectedFilter() { CalFilter *f = mFilters->at(mSelectionCombo->currentItem()); return f; } void KOFilterView::setSelectedFilter(QString filterName) { int filter_num = mSelectionCombo->count(); int i; for (i=0;i<filter_num;i++) { if (mSelectionCombo->text(i)==filterName) mSelectionCombo->setCurrentItem(i); } emit filterChanged(); } void KOFilterView::setSelectedFilter( int fil ) { if ( fil >= mSelectionCombo->count() ) return; mSelectionCombo->setCurrentItem( fil ); emit filterChanged(); } KOCalEditView::KOCalEditView(QWidget* parent, const char* name ) : QScrollView(parent,name) { mw = 0; setResizePolicy( AutoOneFit ); setFrameStyle ( QFrame::Panel | QFrame::Plain ); setLineWidth ( 1 ); setMidLineWidth ( 1 ); setFocusPolicy(NoFocus); } KOCalEditView::~KOCalEditView() { // no need to delete child widgets, Qt does it all for us } void KOCalEditView::selectCal(int id ,bool b) { KOPrefs::instance()->getCalendar( id )->isEnabled = b; emit calendarEnabled ( id, b ); emit needsUpdate(); } void KOCalEditView::selectStdCal( int id, bool b ) { if ( !b ) { KOCalCheckButton* it = (KOCalCheckButton*) sender(); if ( it ) { it->blockSignals( true ); it->setChecked( true ); it->blockSignals( false ); return; } return; } - KOCalCheckButton* sen = (KOCalCheckButton*) sender(); - KOCalCheckButton* it = mStdandardB.first(); + KOCalRadioButton* sen = (KOCalRadioButton*) sender(); + KOCalRadioButton* it = mStdandardB.first(); while ( it ) { if ( it->isChecked() ) { if ( it != sen ) { it->blockSignals( true ); it->setChecked( false ); it->blockSignals( false ); break; } } it = mStdandardB.next(); } KopiCalendarFile * kkf = KOPrefs::instance()->mCalendars.first(); while ( kkf ) { kkf->isStandard = false; kkf = KOPrefs::instance()->mCalendars.next(); } KOPrefs::instance()->getCalendar( id )->isStandard = true; emit setCalendarDefault ( id ); } void KOCalEditView::selectCalAlarm(int id ,bool b ) { KOPrefs::instance()->getCalendar( id )->isAlarmEnabled = b; emit alarmEnabled ( id , b ); emit needsUpdate(); } void KOCalEditView::selectReadOnly(int id ,bool b ) { KOPrefs::instance()->getCalendar( id )->isReadOnly = b; emit calendarReadonly ( id , b ); if ( KOPrefs::instance()->getCalendar( id )->isStandard && b && id > 1 ) { KOPrefs::instance()->getCalendar( id )->isStandard = false; KOPrefs::instance()->getCalendar( 1 )->isStandard = true; emit setCalendarDefault ( 1 ); } emit needsUpdate(); QTimer::singleShot( 0, this, SLOT ( readConfig() ) ); } void KOCalEditView::setColor( const QColor& c, int id ) { KOPrefs::instance()->getCalendar( id )->mDefaultColor = c; emit needsUpdate(); } void KOCalEditView::deleteCal( int id ) { KopiCalendarFile * kkf = KOPrefs::instance()->getCalendar( id ); QString name = kkf->mName; QString file = KGlobal::formatMessage ( kkf->mFileName ,0 ); if ( KMessageBox::warningContinueCancel( this, i18n("The calendar <b>%1</b> is displaying file <b>%2</b>. Do you want to remove this calendar from KO/Pi? (The file is not removed!)").arg(name).arg(file) ) != KMessageBox::Continue ) return; if ( kkf->isStandard ) selectStdCal( 1, true ); emit removeCalendar ( id ); KOPrefs::instance()->mCalendars.remove ( kkf ); emit needsUpdate(); QTimer::singleShot( 0, this, SLOT ( readConfig() ) ); } void KOCalEditView::infoCal( int id ) { QString name = KOPrefs::instance()->getCalendar( id )->mName; QString file = KGlobal::formatMessage ( KOPrefs::instance()->getCalendar( id )->mFileName, 0 ); if ( KOPrefs::instance()->getCalendar( id )->mErrorOnLoad ) { if ( KMessageBox::Yes == KMessageBox::questionYesNo( this, i18n("The calendar <b>%1</b> is not loaded! Loading of file <b>%2</b> failed! <b>Try again to load the calendar?</b>").arg(name).arg(file) ) ) { emit calendarAdded( id ); emit needsUpdate(); QTimer::singleShot( 0, this, SLOT ( readConfig() ) ); } } else KMessageBox::information( this, i18n("The calendar <b>%1</b> is displaying file <b>%2</b>").arg(name).arg(file) ); } void KOCalEditView::readConfig() { mStdandardB.clear(); mEnabledB.clear(); mAlarmB.clear(); mROB.clear(); if ( mw ) delete mw; mw = new QWidget ( viewport() ); addChild(mw); int ii = 0; mainLayout = new QGridLayout ( mw , 2, 8 ); mainLayout->setMargin( 2 ); mainLayout->setSpacing( 2 ); QPushButton * addBut = new QPushButton ( mw ); addBut->setFocusPolicy(NoFocus); mainLayout->addWidget( addBut,0,0 ); - addBut->setPixmap ( SmallIcon("greenhook16")); + addBut->setText( "D"); + connect(addBut,SIGNAL(clicked()),SLOT(defaultInfo())); + //addBut->setPixmap ( SmallIcon("greenhook16")); addBut->setMaximumWidth( addBut->sizeHint().height() ); int max = addBut->sizeHint().height(); addBut = new QPushButton ( mw ); addBut->setFocusPolicy(NoFocus); mainLayout->addWidget( addBut,0,++ii ); addBut->setPixmap ( SmallIcon("eye")); connect(addBut,SIGNAL(clicked()),SLOT(enableAll())); addBut->setMaximumWidth( addBut->sizeHint().height() ); QLabel* lab = new QLabel (i18n(" Calendar \n Resource "), mw ); mainLayout->addWidget( lab,0,++ii ); //lab = new QLabel ( i18n(" "), mw ); //mainLayout->addWidget( lab,0,++ii ); //lab->setFixedWidth( 1 ); addBut = new QPushButton ( mw ); addBut->setFocusPolicy(NoFocus); mainLayout->addWidget( addBut,0,++ii ); addBut->setPixmap ( SmallIcon("bell")); connect(addBut,SIGNAL(clicked()),SLOT(enableAlarm())); addBut->setMaximumWidth( addBut->sizeHint().height() ); addBut = new QPushButton ( mw ); addBut->setFocusPolicy(NoFocus); mainLayout->addWidget( addBut,0,++ii ); addBut->setPixmap ( SmallIcon("pencil")); connect(addBut,SIGNAL(clicked()),SLOT(disableRO())); addBut->setMaximumWidth( addBut->sizeHint().height() ); lab = new QLabel ( "", mw ); mainLayout->addWidget( lab,0,++ii ); addBut = new QPushButton ( mw ); addBut->setFocusPolicy(NoFocus); mainLayout->addWidget( addBut,0,++ii ); addBut->setPixmap ( SmallIcon("plus")); connect(addBut,SIGNAL(clicked()),SLOT(addCal())); lab = new QLabel ( " ", mw ); mainLayout->addWidget( lab,0,++ii ); #if 0 addBut = new QPushButton ( mw ); mainLayout->addWidget( addBut,0,6 ); addBut->setPixmap ( SmallIcon("minus")); connect(addBut,SIGNAL(clicked()),SLOT(deleteAll())); addBut->setMaximumWidth( addBut->sizeHint().height() ); #endif KopiCalendarFile * kkf = KOPrefs::instance()->mCalendars.first(); int row = 1; while ( kkf ) { int iii = 0; - KOCalCheckButton* cb = new KOCalCheckButton( mw ); - mainLayout->addWidget( cb,row,0 );mStdandardB.append( cb ); - cb->setChecked( kkf->isStandard ); - cb->setNum( kkf->mCalNumber ); - connect (cb, SIGNAL (selectNum(int,bool)), SLOT ( selectStdCal(int,bool) ) ); + KOCalRadioButton* rb = new KOCalRadioButton( mw ); + mainLayout->addWidget( rb,row,0 );mStdandardB.append( rb ); + rb->setChecked( kkf->isStandard ); + rb->setNum( kkf->mCalNumber ); + connect (rb, SIGNAL (selectNum(int,bool)), SLOT ( selectStdCal(int,bool) ) ); if ( kkf->mErrorOnLoad || kkf->isReadOnly ) - cb->setEnabled( false ); - cb = new KOCalCheckButton( mw ); + rb->setEnabled( false ); + KOCalCheckButton* cb = new KOCalCheckButton( mw ); mainLayout->addWidget( cb,row,++iii );mEnabledB.append( cb ); cb->setChecked( kkf->isEnabled ); cb->setNum( kkf->mCalNumber ); if ( kkf->mErrorOnLoad ) cb->setEnabled( false ); connect (cb, SIGNAL (selectNum(int,bool)), SLOT ( selectCal(int,bool) ) ); KOCalButton* name = new KOCalButton( mw ); name->setNum( kkf->mCalNumber ); name->setText( kkf->mName ); mainLayout->addWidget( name,row,++iii ); connect (name, SIGNAL (selectNum(int)), SLOT ( infoCal(int) ) ); //lab = new QLabel (" ", mw ); //mainLayout->addWidget( lab,row,++iii ); cb = new KOCalCheckButton( mw ); mainLayout->addWidget( cb,row,++iii );mAlarmB.append( cb ); cb->setChecked( kkf->isAlarmEnabled ); cb->setNum( kkf->mCalNumber ); connect (cb, SIGNAL (selectNum(int,bool)), SLOT ( selectCalAlarm(int,bool) ) ); if ( kkf->mErrorOnLoad ) cb->setEnabled( false ); cb = new KOCalCheckButton( mw ); mainLayout->addWidget( cb,row,++iii );mROB.append( cb ); cb->setChecked( kkf->isReadOnly ); cb->setNum( kkf->mCalNumber ); connect (cb, SIGNAL (selectNum(int,bool)), SLOT ( selectReadOnly(int,bool) ) ); if ( kkf->mErrorOnLoad ) cb->setEnabled( false ); if ( row > 1) { KColorButton *colb = new KColorButton( mw ); mainLayout->addWidget( colb,row,++iii ); colb->setID( kkf->mCalNumber ); colb->setColor( kkf->mDefaultColor ); connect (colb, SIGNAL (changedID(const QColor&, int )), SLOT ( setColor(const QColor&,int) ) ); KOCalButton* calb = new KOCalButton( mw ); mainLayout->addWidget( calb,row,++iii ); calb->setNum( kkf->mCalNumber ); calb->setPixmap ( SmallIcon("minus")); connect (calb, SIGNAL (selectNum(int)), SLOT ( deleteCal(int) ) ); int hei = calb->sizeHint().height(); //calb->setMaximumSize( hei*9/10, hei*9/10 ); } ++row; kkf = KOPrefs::instance()->mCalendars.next(); } lab = new QLabel ( "", mw ); mainLayout->addWidget( lab,row,0 ); mw->show(); } + + +void KOCalEditView::defaultInfo() +{ + KMessageBox::information( this, i18n("Please choose the <b>default calendar</b> in this column. Newly created or imported items are added to the default calendar.") ); +} void KOCalEditView::addCal() { bool tryagain = true; QString name, file; while ( tryagain ) { KONewCalPrefs prefs ( this ); prefs.nameE->setText( name ); prefs.url->setURL( file ); if ( ! prefs.exec() ) return; name = prefs.calName(); file = prefs.calFileName(); tryagain = false; KopiCalendarFile * kkf = KOPrefs::instance()->mCalendars.first(); while ( kkf ) { if ( kkf->mName == name ) { KMessageBox::information( this, i18n("Sorry, the calendar name \n%1\nalready exists!\nPlease choose another name!").arg( name ) ); name = ""; tryagain = true; break; } if ( kkf->mFileName == file ) { KMessageBox::information( this, i18n("Sorry, the file \n%1\nis already loaded!\nPlease choose another file!").arg( KGlobal::formatMessage (file, 0 )) ); tryagain = true; file = ""; break; } kkf = KOPrefs::instance()->mCalendars.next(); } } QFileInfo fi ( file ); if (!fi.exists() ) { if ( KMessageBox::questionYesNo(this, i18n("The file\n%1\ndoes not exist!\nShall I create it for you?").arg( file ) )== KMessageBox::No ) return; QFile fileIn( file ); if (!fileIn.open( IO_WriteOnly ) ) { KMessageBox::sorry( this, i18n("Sorry, cannot create the file\n%1!\nNo calendar added!").arg( file ) ); return; } QTextStream tsIn( &fileIn ); tsIn.setCodec( QTextCodec::codecForName("utf8") ); tsIn << "BEGIN:VCALENDAR\nPRODID:-//KDE-Pim//Platform-independent 2.1.0\nVERSION:2.0\nEND:VCALENDAR\n"; fileIn.close(); } KopiCalendarFile * kkf = KOPrefs::instance()->getNewCalendar(); kkf->mName = name; kkf->mFileName = file; emit calendarAdded( kkf->mCalNumber ); emit needsUpdate(); QTimer::singleShot( 0, this, SLOT ( readConfig() ) ); } void KOCalEditView::enableAll() { toggleList( mEnabledB ); } void KOCalEditView::enableAlarm() { toggleList( mAlarmB ); } void KOCalEditView::disableRO() { toggleList( mROB ); } void KOCalEditView::toggleList ( QPtrList<KOCalCheckButton> list ) { bool dis = false; KOCalCheckButton* it = list.first(); while ( it ) { if ( !it->isChecked() ) { dis = true; break; } it = list.next(); } it = list.first(); while ( it ) { it->setChecked(dis); it = list.next(); } } void KOCalEditView::deleteAll() { qDebug("delteAll"); } diff --git a/korganizer/kofilterview.h b/korganizer/kofilterview.h index 5495d60..b57a6e9 100644 --- a/korganizer/kofilterview.h +++ b/korganizer/kofilterview.h @@ -1,218 +1,248 @@ /* This file is part of KOrganizer. Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #ifndef KOFILTERVIEW_H #define KOFILTERVIEW_H #include <qstring.h> #include <qcheckbox.h> +#include <qradiobutton.h> #include <qlayout.h> #include <qlabel.h> #include <qdialog.h> #include <qscrollview.h> #include <qpushbutton.h> #include <kconfig.h> #include "kofilterview_base.h" #include <libkcal/calfilter.h> #include <kurlrequester.h> #include <klineedit.h> #include <kglobal.h> #include <kmessagebox.h> class QGridLayout; using namespace KCal; class KONewCalPrefs : public QDialog { Q_OBJECT public: KONewCalPrefs( QWidget *parent=0, const char *name=0 ) : QDialog( parent, name, true ) { setCaption( i18n("Add new Calendar") ); QVBoxLayout* lay = new QVBoxLayout( this ); lay->setSpacing( 3 ); lay->setMargin( 3 ); QLabel * lab = new QLabel( i18n("<b>Name of new calendar:</b>"), this ); lay->addWidget( lab ); nameE = new KLineEdit( this ); lay->addWidget( nameE ); lab = new QLabel( i18n("<b>Local ical (*.ics) file:</b>"), this ); lay->addWidget( lab ); url = new KURLRequester ( this ); lay->addWidget( url ); QPushButton * ok = new QPushButton( i18n("OK"), this ); lay->addWidget( ok ); QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); lay->addWidget( cancel ); connect ( ok,SIGNAL(clicked() ),this , SLOT ( checkValid() ) ); connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); setMinimumWidth( 220 ); resize(sizeHint() ); } QString calName() { return nameE->text(); } QString calFileName() { return url->url(); } public slots: void checkValid() { if ( nameE->text().isEmpty() ) { KMessageBox::information( this, i18n("Sorry, the calendar name is empty!") ); nameE->setText( "LPQJ_"+ QString::number( QTime::currentTime().msec () )); return; } if ( url->url().isEmpty() ) { KMessageBox::information( this, i18n("Sorry, the file name is empty!") ); return; } accept(); } public: KLineEdit* nameE; KURLRequester *url; }; class KOCalButton : public QPushButton { Q_OBJECT public: KOCalButton( QWidget *parent=0, const char *name=0 ) : QPushButton( parent, name) { connect( this, SIGNAL( clicked() ), SLOT( bottonClicked() )); mNumber = -1; setFocusPolicy(NoFocus); } void setNum ( int num ) {mNumber = num; } signals: void selectNum ( int ); private: int mNumber; void keyPressEvent ( QKeyEvent * e ) { e->ignore(); } private slots : void bottonClicked() { if ( mNumber > 0 ) emit selectNum ( mNumber ); } }; class KOCalCheckButton : public QCheckBox { Q_OBJECT public: KOCalCheckButton( QWidget *parent=0, const char *name=0 ) : QCheckBox( parent, name) { connect( this, SIGNAL( toggled ( bool ) ), SLOT( bottonClicked( bool ) )); mNumber = -1; setFocusPolicy(NoFocus); //setMaximumWidth( 10 ); } void setNum ( int num ) {mNumber = num; } signals: void selectNum ( int, bool ); private: int mNumber; void keyPressEvent ( QKeyEvent * e ) { e->ignore(); } private slots : void bottonClicked( bool b) { if ( mNumber > 0 ) emit selectNum ( mNumber , b); } }; +class KOCalRadioButton : public QRadioButton +{ + Q_OBJECT + public: + KOCalRadioButton( QWidget *parent=0, const char *name=0 ) : + QRadioButton( parent, name) + { + connect( this, SIGNAL( toggled ( bool ) ), + SLOT( bottonClicked( bool ) )); + mNumber = -1; + setFocusPolicy(NoFocus); + //setMaximumWidth( 10 ); + + } + void setNum ( int num ) {mNumber = num; } + signals: + void selectNum ( int, bool ); +private: + int mNumber; + void keyPressEvent ( QKeyEvent * e ) + { + e->ignore(); + } + +private slots : + void bottonClicked( bool b) { if ( mNumber > 0 ) emit selectNum ( mNumber , b); } +}; + class KOFilterView : public KOFilterView_base { Q_OBJECT public: KOFilterView(QPtrList<CalFilter> *filterList,QWidget* parent=0,const char* name=0, WFlags fl=0); ~KOFilterView(); void updateFilters(); bool filtersEnabled(); void setFiltersEnabled(bool); CalFilter *selectedFilter(); void setSelectedFilter(QString); void setSelectedFilter( int ); signals: void filterChanged(); void editFilters(); private: QPtrList<CalFilter> *mFilters; }; class KOCalEditView : public QScrollView { Q_OBJECT public: KOCalEditView( QWidget* parent=0,const char* name=0); ~KOCalEditView(); public slots: void addCal(); void enableAll(); void enableAlarm(); void disableRO(); void deleteAll(); void selectStdCal(int,bool ); void selectCal(int,bool ); void selectCalAlarm(int,bool ); void selectReadOnly(int,bool ); void setColor(const QColor &,int) ; void deleteCal(int) ; void infoCal(int) ; void readConfig(); + void defaultInfo(); signals: void alarmEnabled ( int cal, bool enable ); void calendarEnabled ( int cal, bool enable ); void calendarReadonly ( int cal, bool readonly ); void setCalendarDefault ( int cal ); void removeCalendar ( int cal ); void calendarAdded( int ); void needsUpdate(); private: QWidget *mw; void toggleList ( QPtrList<KOCalCheckButton> ); - QPtrList<KOCalCheckButton> mStdandardB; + QPtrList<KOCalRadioButton> mStdandardB; QPtrList<KOCalCheckButton> mEnabledB; QPtrList<KOCalCheckButton> mAlarmB; QPtrList<KOCalCheckButton> mROB; QGridLayout* mainLayout; }; #endif // KOFILTERVIEW_H |