Commits

Shlomi Fish committed 89f08c9

Implement buggy drag-and-drop.

It emits a Qt::Variant encoded string instead of a URI. We have to investigate.

Comments (0)

Files changed (1)

LMN-File-Manager/lib/App/LMN/FileBrowserWidget.pm

 use File::Spec;
 use File::stat;
 
+use URI::file;
+
 use QtCore4;
 use QtGui4;
 
     return this->{dir_pathname};
 }
 
+
 sub _populate_tree_with_files
 {
     my $dir_pathname = this->dir_pathname;
 
     closedir ($dh);
 
+    my $item_count = 0;
     foreach my $filename (@entries)
     {
-        my $st = stat( File::Spec->catfile($dir_pathname, $filename) );
+        my $full_path = File::Spec->catfile($dir_pathname, $filename);
+        my $st = stat($full_path);
         this->addTopLevelItem(
             Qt::TreeWidgetItem(
                 [
             )
         );
     }
+    continue
+    {
+        $item_count++;
+    }
 
     return;
 }
 
+sub mimeTypes
+{
+    return ['text/uri-list', 'text-xdnd-username'];
+}
+
+sub mimeData
+{
+    my ($indexes) = @_;
+
+    my $dir_pathname = this->dir_pathname;
+
+    my $mime_data = Qt::MimeData();
+
+    my $encoded_data_uris = Qt::ByteArray();
+    my $encoded_data_users = Qt::ByteArray();
+    my $data_stream_users = Qt::DataStream($encoded_data_users, Qt::IODevice::WriteOnly());
+    my $data_stream_uris = Qt::DataStream($encoded_data_uris, Qt::IODevice::WriteOnly());
+
+    my $username = getpwuid($<);
+
+    foreach my $item (@$indexes)
+    {
+        # For the << operator.
+        no warnings 'void';
+
+        $data_stream_users << $username;
+
+        $data_stream_uris <<
+            (URI::file->new(
+                File::Spec->catfile(
+                    $dir_pathname,
+                    $item->data(0, Qt::DisplayRole()),
+                )
+            )->as_string());
+    }
+
+    $mime_data->setData('text/uri-list', $encoded_data_uris);
+    $mime_data->setData('text-xdnd-username', $encoded_data_users);
+
+    return $mime_data;
+}
+
 sub NEW
 {
     my ( $class, $parent, $args ) = @_;
     $class->SUPER::NEW( $parent );
 
     my $dir_pathname = $args->{dir_pathname};
+
     this->{dir_pathname} = $dir_pathname;
 
     this->setHeaderLabels(["Name", "Size", "Date Modified",]);