summaryrefslogtreecommitdiffstats
path: root/opensuse/tdelibs/fileshare.diff
blob: 86f7d09418d555ed7d450275495c287dfb2dfcd3 (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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
--- kio/kfile/kfilesharedlg.cpp
+++ kio/kfile/kfilesharedlg.cpp	2004/08/06 08:38:31
@@ -24,6 +24,7 @@
 #include <qradiobutton.h>
 #include <qbuttongroup.h>
 #include <qlayout.h>
+#include <qlineedit.h>
 #include <kprocess.h>
 #include <kprocio.h>
 #include <klocale.h>
@@ -93,8 +94,10 @@
     delete m_widget;
     m_rbShare = 0L;
     m_rbUnShare = 0L;
+    m_rbSharerw = 0L;
     m_widget = new QWidget( d->m_vBox );
     QVBoxLayout * vbox = new QVBoxLayout( m_widget );
+    //QHBoxLayout * hbox = new QHBoxLayout( vbox );
 
     switch ( KFileShare::authorization() ) {
     case KFileShare::Authorized:
@@ -105,18 +108,31 @@
             home += '/';
         bool ok = true;
         KFileItemList items = properties->items();
-        // We have 3 possibilities: all shared, all unshared, or mixed.
+        // We have some possibilities: all shared, all unshared (ro,rw), or mixed.
         bool allShared = true;
         bool allUnshared = true;
+        bool allreadonly = true;
         KFileItemListIterator it( items );
         for ( ; it.current() && ok; ++it ) {
             QString path = (*it)->url().path();
+            
+            // 0 => not shared
+            // 1 => shared read only
+            // 3 => shared writeable
+            int dirStatus = KFileShare::isDirectoryShared( path );
             if ( !path.startsWith( home ) )
                 ok = false;
-            if ( KFileShare::isDirectoryShared( path ) )
+            if ( dirStatus == 1 ) {
                 allUnshared = false;
-            else
+            }
+            else if ( dirStatus == 3 ) {
+                allUnshared = false;
+                allreadonly = false;
+            }
+            else {
                 allShared = false;
+                allreadonly = false;
+            }
         }
         if ( !ok )
         {
@@ -136,16 +152,31 @@
             vbox->addWidget( m_rbUnShare, 0 );
             rbGroup->insert( m_rbUnShare );
 
-            m_rbShare = new QRadioButton( i18n("Shared"), m_widget );
+            m_rbShare = new QRadioButton( i18n("Shared - read only for others"), m_widget );
             connect( m_rbShare, SIGNAL( toggled(bool) ), SIGNAL( changed() ) );
             vbox->addWidget( m_rbShare, 0 );
             rbGroup->insert( m_rbShare );
 
+            m_rbSharerw = new QRadioButton( i18n("Shared - writeable for others"), m_widget );
+            connect( m_rbSharerw, SIGNAL( toggled(bool) ), SIGNAL( changed() ) );
+            vbox->addWidget( m_rbSharerw, 0 );
+            rbGroup->insert( m_rbSharerw );
+
+            //QLabel *testlabel1 = new QLabel(i18n("Enter Samba Share Name here"),m_widget);
+            //m_leSmbShareName = new QLineEdit(m_widget);
+            //m_leSmbShareName->setMaxLength(12);
+
+            //hbox->addWidget( testlabel1, 0 );
+            //hbox->addWidget( m_leSmbShareName );
+            //vbox->addLayout( hbox );
+
             // Activate depending on status
             if ( allShared )
-                m_rbShare->setChecked(true);
+                m_rbSharerw->setChecked(true);
             if ( allUnshared )
                 m_rbUnShare->setChecked(true);
+            if ( allreadonly )
+                m_rbShare->setChecked(true);
 
             // Some help text
             QLabel *label = new QLabel( i18n("Sharing this folder makes it available under Linux/UNIX (NFS) and Windows (Samba).") , m_widget );
@@ -204,7 +235,7 @@
 void KFileSharePropsPlugin::applyChanges()
 {
     kdDebug() << "KFileSharePropsPlugin::applyChanges" << endl;
-    if ( m_rbShare && m_rbUnShare )
+    if ( m_rbShare && m_rbUnShare && m_rbSharerw )
     {
         bool share = m_rbShare->isChecked();
         KFileItemList items = properties->items();
@@ -212,7 +243,7 @@
         bool ok = true;
         for ( ; it.current() && ok; ++it ) {
              QString path = (*it)->url().path();
-             ok = setShared( path, share );
+             ok = SuSEsetShared( path, share, m_rbSharerw->isChecked() );
              if (!ok) {
                 if (share)
                   KMessageBox::detailedError(properties,
@@ -239,8 +270,14 @@
 
 bool KFileSharePropsPlugin::setShared( const QString& path, bool shared )
 {
-    kdDebug() << "KFileSharePropsPlugin::setShared " << path << "," << shared << endl;
-    return KFileShare::setShared( path, shared );
+   return SuSEsetShared( path, shared, true );
+}
+
+bool KFileSharePropsPlugin::SuSEsetShared( const QString& path, bool shared, bool readonly )
+{
+    kdDebug() << "KFileSharePropsPlugin::setShared " << path << ","
+              << shared << readonly << endl;
+    return KFileShare::SuSEsetShared( path, shared, readonly );
 }
 
 QWidget* KFileSharePropsPlugin::page() const
--- kio/kfile/kfilesharedlg.h
+++ kio/kfile/kfilesharedlg.h	2004/08/06 08:38:31
@@ -54,10 +54,13 @@
 private:
     void init();
     bool setShared( const QString&path, bool shared );
+    bool SuSEsetShared( const QString&path, bool shared, bool readonly );
 
     QWidget *m_widget;
     QRadioButton *m_rbShare;
+    QRadioButton *m_rbSharerw;
     QRadioButton *m_rbUnShare;
+    //QLineEdit    *m_leSmbShareName;
     QPushButton *m_pbConfig;
     class Private;
     Private *d;
--- kio/kio/kfileshare.cpp
+++ kio/kio/kfileshare.cpp	2004/08/06 08:38:51
@@ -20,6 +20,7 @@
 #include "kfileshare.h"
 #include <qdir.h>
 #include <qfile.h>
+#include <qregexp.h>
 #include <kprocess.h>
 #include <kprocio.h>
 #include <klocale.h>
@@ -35,8 +36,10 @@
 #include <kuser.h>
 
 KFileShare::Authorization KFileShare::s_authorization = NotInitialized;
-QStringList* KFileShare::s_shareList = 0L;
-static KStaticDeleter<QStringList> sdShareList;
+//QStringList* KFileShare::s_shareList = 0L;
+//static KStaticDeleter<QStringList> sdShareList;
+QMap<QString,QString>* KFileShare::s_shareMap = 0L;
+static KStaticDeleter<QMap<QString,QString> > sdShareMap;
 
 KFileShare::ShareMode KFileShare::s_shareMode;
 bool KFileShare::s_sambaEnabled;
@@ -164,10 +167,10 @@
 void KFileShare::readShareList() 
 {
     KFileSharePrivate::self();
-    if ( !s_shareList )
-        sdShareList.setObject( s_shareList, new QStringList );
+    if ( !s_shareMap )
+	sdShareMap.setObject( s_shareMap, new QMap<QString,QString> );
     else
-        s_shareList->clear();
+	s_shareMap->clear();
 
     // /usr/sbin on Mandrake, $PATH allows flexibility for other distributions
     QString exe = findExe( "filesharelist" );
@@ -185,29 +188,45 @@
 
     // Reading code shamelessly stolen from khostname.cpp ;)
     QString line;
+    QString options;
+    QString path;
     int length;
+    QRegExp rx_line("([^\\s]+)\\s+(.*)");
     do {
         length = proc.readln(line, true);
 	if ( length > 0 )
 	{
             if ( line[length-1] != '/' )
                 line += '/';
-            s_shareList->append(line);
+            if( rx_line.search( line ) != -1 ) {
+                options = rx_line.cap(1);
+                path    = rx_line.cap(2);
+                (*s_shareMap)[path] = options;
+            }
             kdDebug(7000) << "Shared dir:" << line << endl;
         }
     } while (length > -1);
 }
 
 
-bool KFileShare::isDirectoryShared( const QString& _path )
+int KFileShare::isDirectoryShared( const QString& _path )
 {
-    if ( ! s_shareList )
+    int ret(0);
+
+    if ( ! s_shareMap )
         readShareList();
 
     QString path( _path );
     if ( path[path.length()-1] != '/' )
         path += '/';
-    return s_shareList && s_shareList->contains( path );
+    //return s_shareList && s_shareList->contains( path );
+    if( (*s_shareMap).contains(path) && !((*s_shareMap)[path].isEmpty()) ) {
+        ret+=1;
+        if( (*s_shareMap)[path].find("readwrite") != -1 )
+            ret+=2;
+    }
+    
+    return ret;
 }
 
 KFileShare::Authorization KFileShare::authorization()
@@ -230,17 +249,30 @@
 
 bool KFileShare::setShared( const QString& path, bool shared )
 {
+   return SuSEsetShared( path, shared, false );
+}
+
+bool KFileShare::SuSEsetShared( const QString& path, bool shared, bool rw )
+{
     if (! KFileShare::sharingEnabled() ||
           KFileShare::shareMode() == Advanced)
        return false;
 
-    kdDebug(7000) << "KFileShare::setShared " << path << "," << shared << endl;
     QString exe = KFileShare::findExe( "fileshareset" );
     if (exe.isEmpty())
         return false;
-        
+
+    // we want to share, so we kick it first - just to be sure
     KProcess proc;
     proc << exe;
+    proc << "--remove";
+    proc << path;
+    proc.start( KProcess::Block );
+    proc.clearArguments();
+        
+    proc << exe;
+     if( rw )
+         proc << "--rw";
     if ( shared )
         proc << "--add";
     else
--- kio/kio/kfileshare.h
+++ kio/kio/kfileshare.h	2004/08/06 08:38:31
@@ -65,7 +65,7 @@
     /**
      * Call this to know if a directory is currently shared
      */
-    static bool isDirectoryShared( const QString& path );
+    static int isDirectoryShared( const QString& path );
 
     enum Authorization { NotInitialized, ErrorNotFound, Authorized, UserNotAllowed };
     /**
@@ -83,7 +83,12 @@
      * @returns wether the perl script was successful
      */
     static bool setShared( const QString& path, bool shared );
-    
+
+    /* 
+     * SuSE only enhancement for now
+     */
+    static bool SuSEsetShared( const QString& path, bool shared, bool ro );
+
     /**
      * The used share mode.
      * Simple means that the simple sharing dialog is used and
@@ -132,7 +137,8 @@
 
 private:
     static Authorization s_authorization;
-    static QStringList* s_shareList;
+//    static QStringList* s_shareList;
+    static QMap<QString,QString>* s_shareMap;
     static ShareMode s_shareMode;
     static bool s_sambaEnabled;
     static bool s_nfsEnabled;