~ubuntu-branches/ubuntu/lucid/kdebase/lucid

« back to all changes in this revision

Viewing changes to kioslave/media/propsdlgplugin/propertiespage.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2008-05-27 12:09:48 UTC
  • mfrom: (1.1.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20080527120948-dottsyd5rcwhzd36
Tags: 4:4.0.80-1ubuntu1
* Merge with Debian
 - remove 97_fix_target_link_libraries.diff
 - Add replaces/conflicts on -kde4 packages

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
  Copyright (c) 2004 Jan Schaefer <j_schaef@informatik.uni-kl.de>
3
 
 
4
 
  This program is free software; you can redistribute it and/or modify
5
 
  it under the terms of the GNU General Public License as published by
6
 
  the Free Software Foundation; either version 2 of the License, or
7
 
  (at your option) any later version.
8
 
 
9
 
  This program is distributed in the hope that it will be useful,
10
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
  GNU General Public License for more details.
13
 
 
14
 
  You should have received a copy of the GNU General Public License
15
 
  along with this program; if not, write to the Free Software
16
 
  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
 
 
18
 
*/
19
 
 
20
 
#include <qcheckbox.h>
21
 
#include <qtooltip.h>
22
 
#include <qbuttongroup.h>
23
 
#include <qlineedit.h>
24
 
#include <qfileinfo.h>
25
 
#include <qlabel.h>
26
 
#include <qregexp.h>
27
 
#include <kpushbutton.h>
28
 
#include <kmessagebox.h>
29
 
#include <klocale.h>
30
 
#include <qcombobox.h>
31
 
#include <qtimer.h>
32
 
#include <kdebug.h>
33
 
#include "propertiespage.h"
34
 
#include <dcopref.h>
35
 
 
36
 
// keep in sync with .ui and kded module
37
 
const char *short_names[] = {"lower", "win95", "winnt", "mixed", 0 };
38
 
const char *journales[] = {"data", "ordered", "writeback", 0 };
39
 
 
40
 
PropertiesPage::PropertiesPage(QWidget* parent, const QString &_id)
41
 
  : PropertiesPageGUI(parent), id(_id)
42
 
{
43
 
  kdDebug() << "props page " << id << endl;
44
 
  DCOPRef mediamanager("kded", "mediamanager");
45
 
  DCOPReply reply = mediamanager.call( "mountoptions", id);
46
 
 
47
 
  QStringList list;
48
 
 
49
 
  if (reply.isValid())
50
 
    list = reply;
51
 
 
52
 
  if (list.size()) {
53
 
    kdDebug() << "list " << list << endl;
54
 
    
55
 
    for (QStringList::ConstIterator it = list.begin(); it != list.end(); ++it)
56
 
      {
57
 
        QString key = (*it).left((*it).find('='));
58
 
        QString value = (*it).mid((*it).find('=') + 1);
59
 
        kdDebug() << "key '" << key << "' value '" << value << "'\n";
60
 
        options[key] = value;
61
 
      }
62
 
 
63
 
    if (!options.contains("ro")) 
64
 
      option_ro->hide();
65
 
    else
66
 
      option_ro->setChecked(options["ro"] == "true");
67
 
    connect( option_ro, SIGNAL( stateChanged(int) ), SIGNAL( changed() ) );
68
 
 
69
 
    if (!options.contains("quiet")) 
70
 
      option_quiet->hide();
71
 
    else
72
 
      option_quiet->setChecked(options["quiet"] == "true");
73
 
    connect( option_quiet, SIGNAL( stateChanged(int) ), SIGNAL( changed() ) );
74
 
 
75
 
    if (!options.contains("sync")) 
76
 
      option_sync->hide();
77
 
    else
78
 
      option_sync->setChecked(options["sync"] == "true");
79
 
    connect( option_sync, SIGNAL( stateChanged(int) ), SIGNAL( changed() ) );
80
 
 
81
 
    if (!options.contains("atime")) 
82
 
      option_atime->hide();
83
 
    else
84
 
      option_atime->setChecked(options["atime"] == "true");
85
 
    connect( option_atime, SIGNAL( stateChanged(int) ), SIGNAL( changed() ) );
86
 
 
87
 
    if (!options.contains("flush")) 
88
 
      option_flush->hide();
89
 
    else
90
 
      option_flush->setChecked(options["flush"] == "true");
91
 
    connect( option_flush, SIGNAL( stateChanged(int) ), SIGNAL( changed() ) );
92
 
 
93
 
    if (!options.contains("utf8")) 
94
 
      option_utf8->hide();
95
 
    else
96
 
      option_utf8->setChecked(options["utf8"] == "true");
97
 
    connect( option_utf8, SIGNAL( stateChanged(int) ), SIGNAL( changed() ) );
98
 
 
99
 
    if (!options.contains("uid")) 
100
 
      option_uid->hide();
101
 
    else
102
 
      option_uid->setChecked(options["uid"] == "true");
103
 
    connect( option_uid, SIGNAL( stateChanged(int) ), SIGNAL( changed() ) );
104
 
 
105
 
    if (!options.contains("shortname")) 
106
 
      {
107
 
        option_shortname->hide();
108
 
        text_shortname->hide();
109
 
      }
110
 
    else 
111
 
      {
112
 
        for (int index = 0; short_names[index]; ++index)
113
 
          if (options["shortname"] == short_names[index]) 
114
 
            {
115
 
              option_shortname->setCurrentItem(index);
116
 
              break;
117
 
            }
118
 
        connect( option_shortname, SIGNAL( activated(int) ), SIGNAL( changed() ) );
119
 
      }
120
 
 
121
 
    if (!options.contains("journaling")) 
122
 
      {
123
 
        text_journaling->hide();
124
 
        option_journaling->hide();
125
 
      } 
126
 
    else
127
 
      {
128
 
        for (int index = 0; journales[index]; ++index)
129
 
          if (options["journaling"] == journales[index]) 
130
 
            {
131
 
              option_journaling->setCurrentItem(index);
132
 
              break;
133
 
            }
134
 
        connect( option_journaling, SIGNAL( activated(int) ), SIGNAL( changed() ) );
135
 
      }
136
 
 
137
 
    label_filesystem->setText(i18n("Filesystem: %1").arg(options["filesystem"]));
138
 
    option_mountpoint->setText(options["mountpoint"]);
139
 
    connect( option_mountpoint, SIGNAL( textChanged( const QString &) ), SIGNAL( changed() ) );
140
 
    option_automount->setChecked(options["automount"] == "true");
141
 
    connect( option_automount, SIGNAL( stateChanged(int) ), SIGNAL( changed() ) );
142
 
 
143
 
    if (!options.contains("journaling") &&
144
 
        !options.contains("shortname") &&
145
 
        !options.contains("uid") &&
146
 
        !options.contains("utf8") &&
147
 
        !options.contains("flush"))
148
 
      groupbox_specific->hide();
149
 
 
150
 
  } else {
151
 
    
152
 
    groupbox_generic->setEnabled(false);
153
 
    groupbox_specific->setEnabled(false);
154
 
    label_filesystem->hide();
155
 
  }
156
 
}
157
 
 
158
 
PropertiesPage::~PropertiesPage() 
159
 
{
160
 
}
161
 
 
162
 
bool PropertiesPage::save() 
163
 
{
164
 
  QStringList result;
165
 
 
166
 
  if (options.contains("ro")) 
167
 
    result << QString("ro=%1").arg(option_ro->isChecked() ? "true" : "false");
168
 
 
169
 
  if (options.contains("quiet")) 
170
 
    result << QString("quiet=%1").arg(option_quiet->isChecked() ? "true" : "false");
171
 
 
172
 
  if (options.contains("sync"))
173
 
    result << QString("sync=%1").arg(option_sync->isChecked() ? "true" : "false");
174
 
 
175
 
  if (options.contains("atime"))
176
 
    result << QString("atime=%1").arg(option_atime->isChecked() ? "true" : "false");
177
 
 
178
 
  if (options.contains("flush"))
179
 
    result << QString("flush=%1").arg(option_flush->isChecked() ? "true" : "false");
180
 
 
181
 
  if (options.contains("utf8"))
182
 
    result << QString("utf8=%1").arg(option_utf8->isChecked() ? "true" : "false");
183
 
 
184
 
  if (options.contains("uid"))
185
 
    result << QString("uid=%1").arg(option_uid->isChecked() ? "true" : "false");
186
 
 
187
 
  if (options.contains("shortname")) 
188
 
    result << QString("shortname=%1").arg(short_names[option_shortname->currentItem()]);
189
 
 
190
 
  if (options.contains("journaling")) 
191
 
    result << QString("journaling=%1").arg(journales[option_journaling->currentItem()]);
192
 
 
193
 
  QString mp = option_mountpoint->text();
194
 
  if (!mp.startsWith("/media/"))
195
 
    {
196
 
      KMessageBox::sorry(this, i18n("Mountpoint has to be below /media"));
197
 
      return false;
198
 
    }
199
 
  result << QString("mountpoint=%1").arg(mp);
200
 
  result << QString("automount=%1").arg(option_automount->isChecked() ? "true" : "false");
201
 
 
202
 
  kdDebug() << result << endl;
203
 
 
204
 
  DCOPRef mediamanager("kded", "mediamanager");
205
 
  DCOPReply reply = mediamanager.call( "setMountoptions", id, result);
206
 
  
207
 
  if (reply.isValid())
208
 
    return (bool)reply;
209
 
  else {
210
 
    KMessageBox::sorry(this,
211
 
                       i18n("Saving the changes failed"));
212
 
    
213
 
    return false;
214
 
  }
215
 
}  
216
 
 
217
 
#include "propertiespage.moc"