libkcal
resourcelocalconfig.cppGo to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <typeinfo>
00024
00025 #include <qlabel.h>
00026 #include <qlayout.h>
00027
00028 #include <klocale.h>
00029 #include <kmessagebox.h>
00030 #include <kdebug.h>
00031 #include <kstandarddirs.h>
00032
00033 #include "vcaldrag.h"
00034 #include "vcalformat.h"
00035 #include "icalformat.h"
00036
00037 #include "resourcelocal.h"
00038
00039 #include "resourcelocalconfig.h"
00040
00041 using namespace KCal;
00042
00043 ResourceLocalConfig::ResourceLocalConfig( QWidget* parent, const char* name )
00044 : KRES::ConfigWidget( parent, name )
00045 {
00046 resize( 245, 115 );
00047 QGridLayout *mainLayout = new QGridLayout( this, 2, 2 );
00048
00049 QLabel *label = new QLabel( i18n( "Location:" ), this );
00050 mURL = new KURLRequester( this );
00051 mainLayout->addWidget( label, 1, 0 );
00052 mainLayout->addWidget( mURL, 1, 1 );
00053
00054 formatGroup = new QButtonGroup( 1, Horizontal, i18n( "Calendar Format" ), this );
00055
00056 icalButton = new QRadioButton( i18n("iCalendar"), formatGroup );
00057 vcalButton = new QRadioButton( i18n("vCalendar"), formatGroup );
00058
00059 mainLayout->addWidget( formatGroup, 2, 1 );
00060 }
00061
00062 void ResourceLocalConfig::loadSettings( KRES::Resource *resource )
00063 {
00064 ResourceLocal* res = static_cast<ResourceLocal*>( resource );
00065 if ( res ) {
00066 mURL->setURL( res->mURL.prettyURL() );
00067 kdDebug(5800) << "Format typeid().name(): " << typeid( res->mFormat ).name() << endl;
00068 if ( typeid( *(res->mFormat) ) == typeid( ICalFormat ) )
00069 formatGroup->setButton( 0 );
00070 else if ( typeid( *(res->mFormat) ) == typeid( VCalFormat ) )
00071 formatGroup->setButton( 1 );
00072 else
00073 kdDebug(5800) << "ERROR: ResourceLocalConfig::loadSettings(): Unknown format type" << endl;
00074 } else
00075 kdDebug(5800) << "ERROR: ResourceLocalConfig::loadSettings(): no ResourceLocal, cast failed" << endl;
00076 }
00077
00078 void ResourceLocalConfig::saveSettings( KRES::Resource *resource )
00079 {
00080 QString url = mURL->url();
00081
00082 if( url.isEmpty() ) {
00083 KStandardDirs dirs;
00084 QString saveFolder = dirs.saveLocation( "data", "korganizer" );
00085 QFile file( saveFolder + "/std.ics" );
00086
00087
00088 for( int i = 0; file.exists(); ++i )
00089 file.setName( saveFolder + "/std" + QString::number(i) + ".ics" );
00090
00091 KMessageBox::information( this, i18n( "You did not specify a URL for this resource. Therefore, the resource will be saved in %1. It is still possible to change this location by editing the resource properties." ).arg( file.name() ) );
00092
00093 url = file.name();
00094 }
00095
00096 ResourceLocal* res = static_cast<ResourceLocal*>( resource );
00097 if (res) {
00098 res->mURL = url;
00099
00100 delete res->mFormat;
00101 if ( icalButton->isOn() ) {
00102 res->mFormat = new ICalFormat();
00103 } else {
00104 res->mFormat = new VCalFormat();
00105 }
00106 } else
00107 kdDebug(5800) << "ERROR: ResourceLocalConfig::saveSettings(): no ResourceLocal, cast failed" << endl;
00108 }
00109
00110 #include "resourcelocalconfig.moc"
|