Fix crash if key bindings specified in profile cannot be found. Improve
[personal-kdebase.git] / apps / kinfocenter / samba / kcmsambaimports.cpp
blobf6220744d9bbd8db21978561dc84af9ddf4c34d8
1 /*
2 * kcmsambaimports.cpp
4 * Copyright (c) 2000 Alexander Neundorf <alexander.neundorf@rz.tu-ilmenau.de>
6 * Requires the Qt widget libraries, available at no cost at
7 * http://www.troll.no/
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include "kcmsambaimports.h"
24 #include "kcmsambaimports.moc"
26 #include <QLayout>
27 #include <QWhatsThis>
29 #include <klocale.h>
30 #include <kdialog.h>
32 #include <stdio.h>
34 ImportsView::ImportsView(QWidget * parent, KConfig *config) :
35 QWidget(parent), configFile(config), list(this) {
36 QBoxLayout *topLayout = new QVBoxLayout(this);
37 topLayout->setMargin(KDialog::marginHint());
38 topLayout->setSpacing(KDialog::spacingHint());
39 topLayout->addWidget(&list);
41 list.setAllColumnsShowFocus(true);
42 list.setShowSortIndicator(true);
43 list.setMinimumSize(425, 200);
44 list.addColumn(i18n("Type"), 50);
45 list.addColumn(i18n("Resource"), 200);
46 list.addColumn(i18n("Mounted Under"), 190);
48 this->setWhatsThis(i18n("This list shows the Samba and NFS shared"
49 " resources mounted on your system from other hosts. The \"Type\""
50 " column tells you whether the mounted resource is a Samba or an NFS"
51 " type of resource. The \"Resource\" column shows the descriptive name"
52 " of the shared resource. Finally, the third column, which is labeled"
53 " \"Mounted under\" shows the location on your system where the shared"
54 " resource is mounted.") );
56 timer.start(10000);
57 QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(updateList()));
58 updateList();
61 void ImportsView::updateList() {
62 list.clear();
63 char *e;
64 char buf[250];
65 QByteArray s(""), strSource, strMount, strType;
66 FILE *f=popen("mount", "r");
67 if (f==0)
68 return;
69 do {
70 e=fgets(buf, 250, f);
71 if (e!=0) {
72 s=buf;
73 if ((s.contains(" nfs ")) || (s.contains(" smbfs "))) {
74 strSource=s.left(s.indexOf(" on /"));
75 strMount=s.mid(s.indexOf(" on /")+4, s.length());
76 if ((s.contains(" nfs ")) || (s.contains("/remote on ")))
77 strType="NFS";
78 else if (s.contains(" smbfs "))
79 strType="SMB";
80 int pos(strMount.indexOf(" type "));
81 if (pos==-1)
82 pos=strMount.indexOf(" read/");
83 strMount=strMount.left(pos);
84 new Q3ListViewItem(&list,strType,strSource,strMount);
87 } while (!feof(f));
88 pclose(f);