add more spacing
[personal-kdebase.git] / apps / konqueror / settings / kio / smbrodlg.cpp
blob82206e165a6ccc66a90de444b9a67710e48240ec
1 /* This file is part of the KDE project
3 Copyright (C) 2000 Alexander Neundorf <neundorf@kde.org>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 // Own
22 #include "smbrodlg.h"
24 // Qt
25 #include <QtCore/QTextCodec>
26 #include <QtGui/QLabel>
27 #include <QtGui/QLayout>
29 // KDE
30 #include <kcharsets.h>
31 #include <kcombobox.h>
32 #include <kconfig.h>
33 #include <kdialog.h>
34 #include <kgenericfactory.h>
35 #include <kglobal.h>
36 #include <klocale.h>
38 #include <config-apps.h>
40 K_PLUGIN_FACTORY_DECLARATION(KioConfigFactory)
42 SMBRoOptions::SMBRoOptions(QWidget *parent, const QVariantList &, const KComponentData &componentData)
43 : KCModule(componentData.isValid() ? componentData : KioConfigFactory::componentData(), parent)
45 QGridLayout *layout = new QGridLayout(this );
46 layout->setMargin( KDialog::marginHint() );
47 layout->setSpacing( KDialog::spacingHint() );
48 QLabel *label=new QLabel(i18n("These settings apply to network browsing only."),this);
49 layout->addWidget(label,0,0, 1, 2 );
51 m_userLe=new QLineEdit(this);
52 label=new QLabel(i18n("Default user name:"),this);
53 label->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
54 label->setBuddy( m_userLe );
55 layout->addWidget(label,1,0);
56 layout->addWidget(m_userLe,1,1);
58 m_passwordLe=new QLineEdit(this);
59 m_passwordLe->setEchoMode(QLineEdit::Password);
60 label=new QLabel(i18n("Default password:"),this);
61 label->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
62 label->setBuddy( m_passwordLe );
63 layout->addWidget(label,2,0);
64 layout->addWidget(m_passwordLe,2,1);
66 /* m_workgroupLe=new QLineEdit(this);
67 label=new QLabel(m_workgroupLe,i18n("Workgroup:"),this);
68 layout->addWidget(label,3,0);
69 layout->addWidget(m_workgroupLe,3,1);
71 m_showHiddenShares=new QCheckBox(i18n("Show hidden shares"),this);
72 layout->addWidget(m_showHiddenShares,4,0, 1, 2 );
74 m_encodingList = new KComboBox( false, this );
75 QStringList _strList = KGlobal::charsets()->availableEncodingNames();
76 m_encodingList->addItems( _strList );
78 label = new QLabel( i18n( "MS Windows encoding:" ), this );
79 label->setBuddy( m_encodingList );
80 layout->addWidget( label, 3, 0 );
81 layout->addWidget( m_encodingList, 3, 1 );
84 layout->addWidget(new QWidget(this),4,0);
86 // connect(m_showHiddenShares, SIGNAL(toggled(bool)), this, SLOT(changed()));
87 connect(m_userLe, SIGNAL(textChanged(const QString&)), this, SLOT(changed()));
88 connect(m_passwordLe, SIGNAL(textChanged(const QString&)), this, SLOT(changed()));
89 // connect(m_workgroupLe, SIGNAL(textChanged(const QString&)), this, SLOT(changed()));
90 // connect( m_encodingList, SIGNAL( activated( const QString & ) ), this , SLOT( changed() ) );
92 layout->setRowStretch(4, 1);
96 SMBRoOptions::~SMBRoOptions()
100 void SMBRoOptions::load()
102 KConfig *cfg = new KConfig("kioslaverc");
104 QString tmp;
105 KConfigGroup group = cfg->group("Browser Settings/SMBro" );
106 m_userLe->setText(group.readEntry("User"));
107 // m_workgroupLe->setText(group.readEntry("Workgroup"));
108 // m_showHiddenShares->setChecked(group.readEntry("ShowHiddenShares", QVariant(false)).toBool());
110 //QStringList _strList = KGlobal::charsets()->availableEncodingNames();
111 //QString m_encoding = QTextCodec::codecForLocale()->name();
112 //m_encodingList->setCurrentIndex( _strList.indexOf( group.readEntry( "Encoding", m_encoding.toLower() ) ) );
114 // unscramble
115 QString scrambled = group.readEntry( "Password" );
116 QString password = "";
117 for (int i=0; i<scrambled.length()/3; i++)
119 QChar qc1 = scrambled[i*3];
120 QChar qc2 = scrambled[i*3+1];
121 QChar qc3 = scrambled[i*3+2];
122 unsigned int a1 = qc1.toLatin1() - '0';
123 unsigned int a2 = qc2.toLatin1() - 'A';
124 unsigned int a3 = qc3.toLatin1() - '0';
125 unsigned int num = ((a1 & 0x3F) << 10) | ((a2& 0x1F) << 5) | (a3 & 0x1F);
126 password[i] = QChar((uchar)((num - 17) ^ 173)); // restore
128 m_passwordLe->setText(password);
130 delete cfg;
133 void SMBRoOptions::save()
135 KConfig *cfg = new KConfig("kioslaverc");
137 KConfigGroup group = cfg->group("Browser Settings/SMBro" );
138 group.writeEntry( "User", m_userLe->text());
139 // group.writeEntry( "Workgroup", m_workgroupLe->text());
140 // group.writeEntry( "ShowHiddenShares", m_showHiddenShares->isChecked());
141 // group.writeEntry( "Encoding", m_encodingList->currentText() );
143 //taken from Nicola Brodu's smb ioslave
144 //it's not really secure, but at
145 //least better than storing the plain password
146 QString password(m_passwordLe->text());
147 QString scrambled;
148 for (int i=0; i<password.length(); i++)
150 QChar c = password[i];
151 unsigned int num = (c.unicode() ^ 173) + 17;
152 unsigned int a1 = (num & 0xFC00) >> 10;
153 unsigned int a2 = (num & 0x3E0) >> 5;
154 unsigned int a3 = (num & 0x1F);
155 scrambled += (char)(a1+'0');
156 scrambled += (char)(a2+'A');
157 scrambled += (char)(a3+'0');
159 group.writeEntry( "Password", scrambled);
161 delete cfg;
164 void SMBRoOptions::defaults()
166 m_userLe->setText("");
167 m_passwordLe->setText("");
168 // m_workgroupLe->setText("");
169 // m_showHiddenShares->setChecked(false);
172 void SMBRoOptions::changed()
174 emit KCModule::changed(true);
177 QString SMBRoOptions::quickHelp() const
179 return i18n("<p><h1>Windows Shares</h1>Konqueror is able to access shared "
180 "Microsoft Windows file systems, if properly configured. If there is a "
181 "specific computer from which you want to browse, fill in "
182 "the <em>Browse server</em> field. This is mandatory if you "
183 "are not running Samba locally. The <em>Broadcast address</em> "
184 "and <em>WINS address</em> fields will also be available, if you "
185 "use the native code, or the location of the 'smb.conf' file "
186 "from which the options are read, when using Samba. In any case, the "
187 "broadcast address (interfaces in smb.conf) must be set up if it "
188 "is guessed incorrectly or you have multiple cards. A WINS server "
189 "usually improves performance, and reduces the network load a lot.</p><p>"
190 "The bindings are used to assign a default user for a given server, "
191 "possibly with the corresponding password, or for accessing specific "
192 "shares. If you choose to, new bindings will be created for logins and "
193 "shares accessed during browsing. You can edit all of them from here. "
194 "Passwords will be stored locally, and scrambled so as to render them "
195 "unreadable to the human eye. For security reasons, you may not want to "
196 "do that, as entries with passwords are clearly indicated as such.</p>");
199 #include "smbrodlg.moc"