kitchensync

memberconfig.cpp

00001 /*
00002     This file is part of KitchenSync.
00003 
00004     Copyright (c) 2005 Cornelius Schumacher <schumacher@kde.org>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "memberconfig.h"
00022 
00023 #include "configgui.h"
00024 #include "memberinfo.h"
00025 
00026 #include <tdelocale.h>
00027 #include <tdemessagebox.h>
00028 
00029 #include <tqlabel.h>
00030 #include <tqlayout.h>
00031 #include <tqtabwidget.h>
00032 
00033 MemberConfig::MemberConfig( TQWidget *parent, const QSync::Member &member )
00034   : TQWidget( parent ), mMember( member )
00035 {
00036   TQBoxLayout *topLayout = new TQVBoxLayout( this );
00037 
00038   mGui = ConfigGui::Factory::create( member, this );
00039   topLayout->addWidget( mGui );
00040 }
00041 
00042 MemberConfig::~MemberConfig()
00043 {
00044 }
00045 
00046 void MemberConfig::loadData()
00047 {
00048   TQByteArray cfg;
00049   QSync::Result error = mMember.configuration( cfg );
00050 
00051   if ( error ) {
00052     KMessageBox::error( this,
00053       i18n("Unable to read config from plugin '%1':\n%2")
00054       .arg( mMember.pluginName() ).arg( error.message() ) );
00055   } else {
00056     TQString txt = TQString::fromUtf8( cfg.data(), cfg.size() );
00057     mGui->load( txt );
00058     MemberInfo mi( mMember );
00059     mGui->setInstanceName( mi.name() );
00060   }
00061 }
00062 
00063 void MemberConfig::saveData()
00064 {
00065   TQString txt = mGui->save();
00066 
00067   if ( txt.isEmpty() ) {
00068     KMessageBox::sorry( this, i18n("Configuration of %1 is empty.").arg( mMember.pluginName() ) );
00069   } else {
00070     TQByteArray cfg = txt.utf8();
00071     cfg.truncate(cfg.size() - 1); /* discard NUL terminator */
00072     mMember.setConfiguration( cfg );
00073     mMember.setName( mGui->instanceName() );
00074     // TODO: Check for save() error.
00075     mMember.save();
00076   }
00077 }
00078 
00079 #include "memberconfig.moc"