~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kinfocenter/Modules/samba/kcmsambaimports.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * kcmsambaimports.cpp
 
3
 *
 
4
 * Copyright (c) 2000 Alexander Neundorf <alexander.neundorf@rz.tu-ilmenau.de>
 
5
 *
 
6
 * Requires the Qt widget libraries, available at no cost at
 
7
 * http://www.troll.no/
 
8
 *
 
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.
 
13
 *
 
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.
 
18
 *
 
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.
 
22
 */
 
23
#include "kcmsambaimports.h"
 
24
#include "kcmsambaimports.moc"
 
25
 
 
26
#include <QLayout>
 
27
#include <QWhatsThis>
 
28
 
 
29
#include <klocale.h>
 
30
#include <kdialog.h>
 
31
 
 
32
#include <stdio.h>
 
33
 
 
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);
 
40
 
 
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);
 
47
 
 
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.") );
 
55
 
 
56
        timer.start(10000);
 
57
        QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(updateList()));
 
58
        updateList();
 
59
}
 
60
 
 
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);
 
85
                        };
 
86
                };
 
87
        } while (!feof(f));
 
88
        pclose(f);
 
89
}
 
90