summaryrefslogtreecommitdiffstats
path: root/kiosktool/kioskConfigDialog.cpp
blob: 8b523bbcb67cf716daf14f7ce956f9e360ddfad7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
 *   kioskConfigDialog.cpp
 *
 *   Copyright (C) 2004 Waldo Bastian <bastian@kde.org>
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License version 2 as
 *   published by the Free Software Foundation.
 *
 *   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.
 */

#include "kioskConfigDialog.h"

#include <qcheckbox.h>
#include <qtextedit.h>

#include <kapplication.h>
#include <kconfig.h>
#include <kfiledialog.h>
#include <knuminput.h>
#include <klineedit.h>
#include <klocale.h>
#include <kurlrequester.h>

#include "kioskrun.h"

#include "kioskConfigDialog_ui.h"

KioskConfigDialog::KioskConfigDialog(QWidget *parent)
 : KDialogBase(parent, "KioskConfigDialog", true, i18n("Configure Kiosk Admin Tool"),
   KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, true )
{
  w = new KioskConfigDialogUI(this);
  w->lineProfilePrefix->setMode(KFile::Directory | KFile::LocalOnly);
  w->lineUpload->setMode(KFile::Directory);

  setMainWidget(w);
  
  init();
  connect(w->lineProfilePrefix, SIGNAL(textChanged( const QString& )), SLOT(updateExample()));
  connect(w->lineUpload, SIGNAL(textChanged( const QString& )), SLOT(updateExample()));
  connect(w->lineUploadPrefix, SIGNAL(textChanged( const QString& )), SLOT(updateExample()));
}

KioskConfigDialog::~KioskConfigDialog()
{
}

void KioskConfigDialog::init()
{
   QString prefix = KioskRun::self()->getProfilePrefix();
   
   if (prefix.isEmpty())
   {
      w->checkProfilePrefix->setChecked(false);
      w->lineProfilePrefix->setURL("/etc/kde-profile/");
   }
   else
   {
      w->checkProfilePrefix->setChecked(true);
      w->lineProfilePrefix->setURL(prefix);
   }
   
   KConfig *config = kapp->config();
   config->setGroup("General");
   
   QString uploadURL = config->readEntry("uploadURL");
   if (uploadURL.isEmpty())
   {
      w->checkUpload->setChecked(false);
      w->lineUpload->setURL("fish://root@host/");
   }
   else
   {
      w->checkUpload->setChecked(true);
      w->lineUpload->setURL(uploadURL);
   }
   w->lineUploadPrefix->setText(config->readEntry("uploadPrefix"));
   
   int minUID = config->readNumEntry("FirstUIDShown", 500);
   if (!minUID)
   {
      w->checkUID->setChecked(false);
      w->numUID->setValue(500);
   }
   else
   {
      w->checkUID->setChecked(true);
      w->numUID->setValue(minUID);
   }
   
   updateExample();   
}

void KioskConfigDialog::updateExample()
{
   QString uploadPrefix = w->lineUploadPrefix->text();
   QString file1 = w->lineProfilePrefix->url()+"default";
   QString file2 = file1;
   if (file2.startsWith(uploadPrefix))
      file2 = file2.mid(uploadPrefix.length());
   if (file2.startsWith("/"))
      file2 = file2.mid(1);
   QString url = w->lineUpload->url();
   if (!url.endsWith("/"))
      url += "/";
   url += file2;
   QString example = QString("<qt><center><b>%1</b><br>--><br><b>%2</b></center>").arg(file1, url);
   w->lblUploadExample->setText(example);
   w->lblUploadExample->setFixedSize(QSize(500,fontMetrics().lineSpacing()*3 + 6));
}

bool KioskConfigDialog::save()
{
   QString uploadURL;
   QString uploadPrefix;
   QString prefix;
   int minUID = 0;
   
   uploadPrefix = w->lineUploadPrefix->text();

   if (w->checkUpload->isChecked())
      uploadURL = w->lineUpload->url();
      
   if (w->checkProfilePrefix->isChecked())
      prefix = w->lineProfilePrefix->url();

   if (w->checkUID->isChecked())
      minUID = w->numUID->value();
   
   KConfig *config = kapp->config();
   config->setGroup("General");
   config->writeEntry("uploadURL", uploadURL);
   config->writeEntry("uploadPrefix", uploadPrefix);
   config->writeEntry("FirstUIDShown", minUID);
   config->sync();
   
   return KioskRun::self()->setProfilePrefix(prefix);
}

#include "kioskConfigDialog.moc"