Bug 141498 - Changing permissions of multiple selected files / directories.
Summary: Changing permissions of multiple selected files / directories.
Status: RESOLVED FIXED
Alias: None
Product: kftpgrabber
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Gentoo Packages Linux
: NOR normal
Target Milestone: ---
Assignee: Jernej Kos
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-02-10 19:24 UTC by Christoph Tavan
Modified: 2007-02-10 22:16 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christoph Tavan 2007-02-10 19:24:41 UTC
Version:            (using KDE KDE 3.5.5)
Installed from:    Gentoo Packages
OS:                Linux

Recursive chmod has been added with http://bugs.kde.org/show_bug.cgi?id=123762 .

However when I select multiple files and/or directories and want to change the permissions of _all_ of the selected files / dirs _only_ the permissions of the first file / dir are changed and all the others remain unchanged.

It would be great, if the user could change the permissions of many selected files at a time.
Comment 1 Jernej Kos 2007-02-10 22:16:34 UTC
SVN commit 632365 by kostko:

Implemented properties for multiple selected items.

BUG: 141498

 M  +11 -6     actions.cpp  
 M  +113 -74   propsplugin.cpp  
 M  +9 -12     propsplugin.h  


--- trunk/extragear/network/kftpgrabber/src/widgets/browser/actions.cpp #632364:632365
@@ -423,15 +423,20 @@
   }
 
   // Show the dialog
+  KPropertiesDialog *propsDialog;
+  
   if (item->isLocalFile()) {
-    KPropertiesDialog *propsDialog = new KPropertiesDialog(item);
-    propsDialog->exec();
+    if (selectedItems->count() == 0)
+      propsDialog = new KPropertiesDialog(item);
+    else
+      propsDialog = new KPropertiesDialog(*selectedItems);
   } else {
-    KPropertiesDialog *propsDialog = new KPropertiesDialog(item->name());
-    propsDialog->insertPlugin(new KFTPWidgets::Browser::PropsPlugin(propsDialog, item));
-    propsDialog->insertPlugin(new KFTPWidgets::Browser::PermissionsPropsPlugin(propsDialog, item, m_view->getSession()));
-    propsDialog->exec();
+    propsDialog = new KPropertiesDialog(item->name());
+    propsDialog->insertPlugin(new KFTPWidgets::Browser::PropsPlugin(propsDialog, *selectedItems));
+    propsDialog->insertPlugin(new KFTPWidgets::Browser::PermissionsPropsPlugin(propsDialog, *selectedItems, m_view->getSession()));
   }
+  
+  propsDialog->exec();
 }
 
 void Actions::addPriorityItems(int priority)
--- trunk/extragear/network/kftpgrabber/src/widgets/browser/propsplugin.cpp #632364:632365
@@ -52,47 +52,73 @@
 
 namespace Browser {
 
-PropsPlugin::PropsPlugin(KPropertiesDialog *_props, KFileItem *item)
- : KPropsDlgPlugin(_props),
-   m_item(item)
+PropsPlugin::PropsPlugin(KPropertiesDialog *props, KFileItemList items)
+ : KPropsDlgPlugin(props)
 {
   QFrame *frame = properties->addPage(i18n("&General"));
   frame->setMinimumWidth(320);
   frame->setMinimumHeight(300);
   
+  // Some differences between a single file and multiple files
+  KFileItem *item = items.at(0);
   KURL fileUrl = item->url();
+  filesize_t fileSize = item->size();
+  QString nameText;
   QString iconText;
   QString mimeComment;
-  bool isDir = false;
   
-  // Guess file type
-  if (item->isDir()) {
-    iconText = "folder";
-    isDir = true;
-    mimeComment = i18n("Remote folder");
-  } else if (item->isLink()) {
-    // We can't know if the sym-linked file is realy a directory, but most of
-    // the time it is. So if we can't determine the MIME type, set it to directory.
-    KMimeType::Ptr mimeType = KMimeType::findByURL(fileUrl, 0, false, true);
+  if (items.count() == 1) {
+    bool isDir = false;
     
-    if (mimeType->name() == KMimeType::defaultMimeType()) {
+    // Guess file type
+    if (item->isDir()) {
       iconText = "folder";
       isDir = true;
       mimeComment = i18n("Remote folder");
+    } else if (item->isLink()) {
+      // We can't know if the sym-linked file is realy a directory, but most of
+      // the time it is. So if we can't determine the MIME type, set it to directory.
+      KMimeType::Ptr mimeType = KMimeType::findByURL(fileUrl, 0, false, true);
+      
+      if (mimeType->name() == KMimeType::defaultMimeType()) {
+        iconText = "folder";
+        isDir = true;
+        mimeComment = i18n("Remote folder");
+      } else {
+        iconText = mimeType->icon(QString::null, false);
+        mimeComment = mimeType->comment();
+      }
     } else {
+      KMimeType::Ptr mimeType = KMimeType::findByURL(fileUrl, 0, false, true);
       iconText = mimeType->icon(QString::null, false);
       mimeComment = mimeType->comment();
     }
+    
+    if (mimeComment.isEmpty()) {
+      mimeComment = i18n("Unknown");
+    }
+    
+    nameText = item->name();
   } else {
-    KMimeType::Ptr mimeType = KMimeType::findByURL(fileUrl, 0, false, true);
-    iconText = mimeType->icon(QString::null, false);
-    mimeComment = mimeType->comment();
+    // Count files and folders selected
+    int countFiles = 0;
+    int countFolders = 0;
+    fileSize = 0;
+    
+    KFileItemListIterator i(items);
+    for (; i.current(); ++i) {
+      if ((*i)->isDir())
+        countFolders++;
+      else
+        countFiles++;
+      
+      fileSize += (*i)->size();
+    }
+    
+    iconText = "kmultiple";
+    nameText = KIO::itemsSummaryString(countFiles + countFolders, countFiles, countFolders, 0, false);
   }
   
-  if (mimeComment.isEmpty()) {
-    mimeComment = i18n("Unknown");
-  }
-  
   QVBoxLayout *vbl = new QVBoxLayout(frame, 0, KDialog::spacingHint(), "vbl");
   QGridLayout *grid = new QGridLayout(0, 3);
   grid->setColStretch(0, 0);
@@ -101,7 +127,7 @@
   grid->addColSpacing(1, KDialog::spacingHint());
   vbl->addLayout(grid);
   
-  // BEGIN first part
+  // Display file name and icon
   QLabel *iconLabel = new QLabel(frame);
   int bsize = 66 + 2 * iconLabel->style().pixelMetric(QStyle::PM_ButtonMargin);
   iconLabel->setFixedSize(bsize, bsize);
@@ -109,58 +135,58 @@
   grid->addWidget(iconLabel, 0, 0, AlignLeft);
   
   QLabel *nameLabel = new QLabel(frame);
-  nameLabel->setText(item->name());
+  nameLabel->setText(nameText);
   grid->addWidget(nameLabel, 0, 2);
   
   KSeparator *sep = new KSeparator(KSeparator::HLine, frame);
   grid->addMultiCellWidget(sep, 2, 2, 0, 2);
-  // END first part
   
-  // BEGIN second part
-  QLabel *l = new QLabel(i18n("Type:"), frame);
-  grid->addWidget(l, 3, 0);
+  // Display file information
+  QLabel *l;
+  int currentRow = 3;
   
-  l = new QLabel(mimeComment, frame);
-  grid->addWidget(l, 3, 2);
+  if (items.count() == 1) {
+    l = new QLabel(i18n("Type:"), frame);
+    grid->addWidget(l, currentRow, 0);
+    
+    l = new QLabel(mimeComment, frame);
+    grid->addWidget(l, currentRow++, 2);
+  }
   
   l = new QLabel(i18n("Location:"), frame);
-  grid->addWidget(l, 4, 0);
+  grid->addWidget(l, currentRow, 0);
   
   l = new KSqueezedTextLabel(frame);
   l->setText(fileUrl.directory());
-  grid->addWidget(l, 4, 2);
+  grid->addWidget(l, currentRow++, 2);
   
   l = new QLabel(i18n("Size:"), frame);
-  grid->addWidget(l, 5, 0);
+  grid->addWidget(l, currentRow, 0);
   
   l = new QLabel(frame);
-  grid->addWidget(l, 5, 2);
+  grid->addWidget(l, currentRow++, 2);
   
-  l->setText(QString::fromLatin1("%1 (%2)").arg(KIO::convertSize(item->size()))
-             .arg(KGlobal::locale()->formatNumber(item->size(), 0)));
-             
+  l->setText(QString::fromLatin1("%1 (%2)").arg(KIO::convertSize(fileSize))
+             .arg(KGlobal::locale()->formatNumber(fileSize, 0)));
+  
   sep = new KSeparator(KSeparator::HLine, frame);
-  grid->addMultiCellWidget(sep, 6, 6, 0, 2);
-  // END second part
+  grid->addMultiCellWidget(sep, currentRow, currentRow, 0, 2);
+  currentRow++;
   
-  // BEGIN third part
-  l = new QLabel(i18n("Created:"), frame);
-  grid->addWidget(l, 7, 0);
+  // Display modification time
+  if (items.count() == 1) {
+    l = new QLabel(i18n("Created:"), frame);
+    grid->addWidget(l, currentRow, 0);
+    
+    QDateTime dt;
+    dt.setTime_t(item->time(KIO::UDS_MODIFICATION_TIME));
+    l = new QLabel(KGlobal::locale()->formatDateTime(dt), frame);
+    grid->addWidget(l, currentRow++, 2);
+  }
   
-  QDateTime dt;
-  dt.setTime_t(item->time(KIO::UDS_MODIFICATION_TIME));
-  l = new QLabel(KGlobal::locale()->formatDateTime(dt), frame);
-  grid->addWidget(l, 7, 2);
-  // END third part
-  
   vbl->addStretch(1);
 }
 
-
-PropsPlugin::~PropsPlugin()
-{
-}
-
 void PropsPlugin::applyChanges()
 {
 }
@@ -171,9 +197,9 @@
   {S_IROTH, S_IWOTH, S_IXOTH, S_ISVTX}
 };
 
-PermissionsPropsPlugin::PermissionsPropsPlugin(KPropertiesDialog *_props, KFileItem *item, KFTPSession::Session *session)
+PermissionsPropsPlugin::PermissionsPropsPlugin(KPropertiesDialog *_props, KFileItemList items, KFTPSession::Session *session)
   : KPropsDlgPlugin(_props),
-    m_item(item),
+    m_items(items),
     m_session(session),
     m_cbRecursive(0)
 {
@@ -181,19 +207,32 @@
   frame->setMinimumWidth(320);
   frame->setMinimumHeight(300);
   
+  // Some differences between a single file and multiple files
+  KFileItem *item = items.at(0);
   KURL fileUrl = item->url();
   bool isDir = false;
   
-  // Guess file type
-  if (item->isDir()) {
-    isDir = true;
-  } else if (item->isLink()) {
-    // We can't know if the sym-linked file is realy a directory, but most of
-    // the time it is. So if we can't determine the MIME type, set it to directory.
-    KMimeType::Ptr mimeType = KMimeType::findByURL(fileUrl, 0, false, true);
-    
-    if (mimeType->name() == KMimeType::defaultMimeType())
+  if (items.count() == 1) {
+    // Guess file type
+    if (item->isDir()) {
       isDir = true;
+    } else if (item->isLink()) {
+      // We can't know if the sym-linked file is realy a directory, but most of
+      // the time it is. So if we can't determine the MIME type, set it to directory.
+      KMimeType::Ptr mimeType = KMimeType::findByURL(fileUrl, 0, false, true);
+      
+      if (mimeType->name() == KMimeType::defaultMimeType())
+        isDir = true;
+    }
+  } else {
+    // Check for directories
+    KFileItemListIterator i(items);
+    for (; i.current(); ++i) {
+      if ((*i)->isDir()) {
+        isDir = true;
+        break;
+      }
+    }
   }
   
   QBoxLayout *box = new QVBoxLayout(frame, 0, KDialog::spacingHint());
@@ -253,7 +292,7 @@
   
   mode_t permissions = item->permissions();
   
-  // BEGIN checkboxes
+  // Display checkboxes
   for (int row = 0; row < 3; ++row) {
     for (int col = 0; col < 4; ++col) {
       QCheckBox *cb = new QCheckBox(gb);
@@ -264,21 +303,17 @@
       gl->addWidget(cb, row + 2, col + 1);
     }
   }
-  // END checkboxes  
+  
   gl->setColStretch(6, 10);
   box->addStretch(10);
   
-  if (item->isDir()) {
+  if (isDir) {
     m_cbRecursive = new QCheckBox(i18n("Apply changes to all subfolders and their contents"), frame);
     connect(m_cbRecursive, SIGNAL(clicked()), this, SLOT(changed()));
     box->addWidget(m_cbRecursive);
   }
 }
 
-PermissionsPropsPlugin::~PermissionsPropsPlugin()
-{
-}
-
 void PermissionsPropsPlugin::applyChanges()
 {
   // Generate new permissions =)
@@ -307,11 +342,15 @@
   
   // Actually do a chmod
   int mode = newPerms[0] * 1000 + newPerms[1] * 100 + newPerms[2] * 10 + newPerms[3];
+  bool recursive = m_cbRecursive && m_cbRecursive->isChecked();
   
-  if (m_cbRecursive && m_cbRecursive->isChecked())
-    m_session->getClient()->chmod(m_item->url(), mode, true);
-  else
-    m_session->getClient()->chmod(m_item->url(), mode);
+  KFileItemListIterator i(m_items);
+  for (; i.current(); ++i) {
+    if ((*i)->isDir())
+      m_session->getClient()->chmod((*i)->url(), mode, recursive);
+    else
+      m_session->getClient()->chmod((*i)->url(), mode);
+  }
 }
 
 }
--- trunk/extragear/network/kftpgrabber/src/widgets/browser/propsplugin.h #632364:632365
@@ -54,7 +54,8 @@
 namespace Browser {
 
 /**
- * This is a plugin for displaying remote file properties using standard KDE file properties dialog.
+ * This is a plugin for displaying remote file properties using the
+ * standard KDE file properties dialog.
  *
  * @author Jernej Kos
  */
@@ -62,17 +63,14 @@
 {
 Q_OBJECT
 public:
-    PropsPlugin(KPropertiesDialog *_props, KFileItem *item);
-    ~PropsPlugin();
+    PropsPlugin(KPropertiesDialog *props, KFileItemList items);
     
-    virtual void applyChanges();
-private:
-    KFileItem *m_item;
+    void applyChanges();
 };
 
 /**
- * This is a plugin for displaying remote file permissions and their changing using the standard KDE
- * file properties dialog.
+ * This is a plugin for displaying remote file permissions and their
+ * changing using the standard KDE file properties dialog.
  *
  * @author Jernej Kos
  */
@@ -80,12 +78,11 @@
 {
 Q_OBJECT
 public:
-    PermissionsPropsPlugin(KPropertiesDialog *_props, KFileItem *item, KFTPSession::Session *session);
-    ~PermissionsPropsPlugin();
+    PermissionsPropsPlugin(KPropertiesDialog *props, KFileItemList items, KFTPSession::Session *session);
     
-    virtual void applyChanges();
+    void applyChanges();
 private:
-    KFileItem *m_item;
+    KFileItemList m_items;
     KFTPSession::Session *m_session;
     
     static mode_t fperm[3][4];