kitchensync

memberconfig.cpp
1 /*
2  This file is part of KitchenSync.
3 
4  Copyright (c) 2005 Cornelius Schumacher <schumacher@kde.org>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20 
21 #include "memberconfig.h"
22 
23 #include "configgui.h"
24 #include "memberinfo.h"
25 
26 #include <tdelocale.h>
27 #include <tdemessagebox.h>
28 
29 #include <tqlabel.h>
30 #include <tqlayout.h>
31 #include <tqtabwidget.h>
32 
33 MemberConfig::MemberConfig( TQWidget *parent, const QSync::Member &member )
34  : TQWidget( parent ), mMember( member )
35 {
36  TQBoxLayout *topLayout = new TQVBoxLayout( this );
37 
38  mGui = ConfigGui::Factory::create( member, this );
39  topLayout->addWidget( mGui );
40 }
41 
42 MemberConfig::~MemberConfig()
43 {
44 }
45 
46 void MemberConfig::loadData()
47 {
48  TQByteArray cfg;
49  QSync::Result error = mMember.configuration( cfg );
50 
51  if ( error ) {
52  KMessageBox::error( this,
53  i18n("Unable to read config from plugin '%1':\n%2")
54  .arg( mMember.pluginName() ).arg( error.message() ) );
55  } else {
56  TQString txt = TQString::fromUtf8( cfg.data(), cfg.size() );
57  mGui->load( txt );
58  MemberInfo mi( mMember );
59  mGui->setInstanceName( mi.name() );
60  }
61 }
62 
63 void MemberConfig::saveData()
64 {
65  TQString txt = mGui->save();
66 
67  if ( txt.isEmpty() ) {
68  KMessageBox::sorry( this, i18n("Configuration of %1 is empty.").arg( mMember.pluginName() ) );
69  } else {
70  TQByteArray cfg = txt.utf8();
71  cfg.truncate(cfg.size() - 1); /* discard NUL terminator */
72  mMember.setConfiguration( cfg );
73  mMember.setName( mGui->instanceName() );
74  // TODO: Check for save() error.
75  mMember.save();
76  }
77 }
78 
79 #include "memberconfig.moc"