summaryrefslogtreecommitdiffstats
path: root/kiosktool/profilePropsPage.cpp
blob: 4396218f274cb222db3135ee9796549960595fcd (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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*
 *   profilePropsPage.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 "profilePropsPage.h"

#include <tqcombobox.h>
#include <tqvalidator.h>

#include <kapplication.h>
#include <kconfig.h>
#include <klineedit.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kurlrequester.h>
#include <kuser.h>

#include "kioskrun.h"
#include "kiosksync.h"

static TQStringList userList()
{
   KUser thisUser;
   TQStringList result;
   result << thisUser.loginName();
   result << "root";

   KConfig *config = kapp->config();
   config->setGroup("General");
   result += config->readListEntry("PreviousUsers");
   result.sort();

   // Remove dupes
   TQStringList::Iterator nextIt = result.begin();
   for(TQStringList::Iterator it = result.begin();
       it != result.end(); it = nextIt)
   {
      nextIt = it;
      nextIt++;

      if ((nextIt != result.end()) && ((*it) == (*nextIt)))
         result.remove(it);
   }

   return result;
}


ProfilePropsPage::ProfilePropsPage(TQWidget *parent, const TQString &profile)
 : ProfilePropsPageUI(parent), PageWidget(this), m_profile(profile)
{
}

ProfilePropsPage::~ProfilePropsPage()
{
}

void ProfilePropsPage::slotProfileNameChanged()
{
  TQString profile = editProfileName->text();
  if (m_fixedProfileDir)
  {
    TQString profilePrefix = KioskRun::self()->getProfilePrefix();
    TQString installDir = profilePrefix+profile+"/";
    labelInstallDir->setText(installDir);
  }
// TODO:  enableButtonOK(!profile.isEmpty());
}

void ProfilePropsPage::load()
{
  bool bNewProfile = false;
  if (m_profile.isEmpty())
  {
    m_profile = KioskRun::self()->newProfile();
    bNewProfile = true;
  }

  TQString profilePrefix = KioskRun::self()->getProfilePrefix();
  m_fixedProfileDir = !profilePrefix.isEmpty();
  connect(editProfileName, TQT_SIGNAL(textChanged(const TQString&)),
          this, TQT_SLOT(slotProfileNameChanged()));
  
#if 0
  connect(kurlInstallDir, TQT_SIGNAL(textChanged(const TQString&)),
          this, TQT_SLOT(updateButtons()));
#endif

  comboUser->setEditable(true);
  comboUser->insertStringList(userList());

  TQRegExp rx( "[^/ :]*" );
  TQValidator* validator = new TQRegExpValidator( rx, this );

  editProfileName->setValidator(validator);
  editProfileName->setFocus();

  TQString description;
  TQString installDir;
  TQString installUser;

  KioskRun::self()->getProfileInfo(m_profile, description, installDir, installUser);

  if (!bNewProfile)
  {
     m_origProfile = m_profile;
     m_origInstallDir = installDir;
  }

  editProfileName->setText(m_profile);
  editDescription->setText(description);
  if (m_fixedProfileDir)
  {
    delete kurlInstallDir;
    labelInstallDir->setReadOnly(true);
    labelInstallDir->setText(installDir);
    setTabOrder(editDescription, comboUser);
    setTabOrder(comboUser, labelInstallDir);
  }
  else
  {
    delete labelInstallDir;
    kurlInstallDir->setMode(KFile::Directory);
    kurlInstallDir->setURL(installDir);
    setTabOrder(editDescription, comboUser);
    setTabOrder(comboUser, kurlInstallDir);
  }
  comboUser->setCurrentText(installUser);
}

bool ProfilePropsPage::save()
{
  TQString user = comboUser->currentText();
  KUser userInfo(user);
  if (!userInfo.isValid())
  {
     KMessageBox::sorry(this,
       i18n("<qt>The user <b>%1</b> is not an existing user.</qt>").tqarg(user));
     comboUser->setFocus();
     return false;
  }
     
  m_profile = editProfileName->text();
  TQString description = editDescription->text();
  TQString installDir;
  if (m_fixedProfileDir)
  {
    installDir = labelInstallDir->text();
  }
  else
  {
    installDir = kurlInstallDir->url();
  }
  
  if (!installDir.endsWith("/"))
    installDir.append("/");

  if (!m_origInstallDir.isEmpty() && (installDir != m_origInstallDir))
  {
    KioskSync origInstallDir;
    origInstallDir.addDir(m_origInstallDir, KURL());
    TQStringList fileList = origInstallDir.listFiles();
    fileList.remove(".kdeprofile");
    if (!fileList.isEmpty())
    {
       int msgResult = KMessageBox::warningContinueCancelList(this,
                          i18n("<qt>The directory for this profile has changed "
                               "from <b>%1</b> to <b>%2</b>.<p>"
                               "The following files under <b>%3</b> will be moved to <b>%4</b>")
                               .tqarg(m_origInstallDir, installDir, m_origInstallDir, installDir),
                          fileList,
                          i18n("Profile Directory Changed"));
       if (msgResult != KMessageBox::Continue)
          return false;
    }
    KioskRun::self()->setUser(user);
    if (!KioskRun::self()->move(m_origInstallDir, installDir, fileList))
       return false;
    if (TQDir(m_origInstallDir).exists())
    {
       if (!KioskRun::self()->remove(m_origInstallDir))
          return false;
    }
  }

  TQString installUser = user;

  bool result = KioskRun::self()->setProfileInfo( m_profile, description, installDir, installUser);

  if (result && !m_origProfile.isEmpty() && (m_origProfile != m_profile))
  {
     result = KioskRun::self()->deleteProfile( m_origProfile, false );
  }

  // Store this user for easy access later
  KConfig *config = kapp->config();
  config->setGroup("General");
  TQStringList previousUsers= config->readListEntry("PreviousUsers");
  if (!previousUsers.contains(user))
  {
     previousUsers << user;
     config->writeEntry("PreviousUsers", previousUsers);
     config->sync();
  }

  return result;
}

void ProfilePropsPage::setFocus()
{
  editProfileName->setFocus();
}

TQString ProfilePropsPage::subCaption()
{
  return TQString();
}

#include "profilePropsPage.moc"