Commits

Shlomi Fish committed 2340b85

Extract a class for FileBrowserWidget.

Comments (0)

Files changed (2)

App-Qt-AdHocFileManager/lib/App/Qt/AdHocFileManager/FileBrowserWidget.pm

+package App::Qt::AdHocFileManager::FileBrowserWidget;
+
+use strict;
+use warnings;
+use autodie;
+
+use utf8;
+
+use File::Spec;
+use File::stat;
+
+use QtCore4;
+use QtGui4;
+
+use QtCore4::isa qw( Qt::TreeWidget );
+use QtCore4::slots update => [];
+
+sub dir_pathname
+{
+    return this->{dir_pathname};
+}
+
+sub _populate_tree_with_files
+{
+    my $dir_pathname = this->dir_pathname;
+
+    my $dh;
+    opendir $dh, $dir_pathname;
+
+    my @entries = sort (File::Spec->no_upwards(readdir($dh)));
+
+    closedir ($dh);
+
+    foreach my $filename (@entries)
+    {
+        my $st = stat( File::Spec->catfile($dir_pathname, $filename) );
+        this->addTopLevelItem(Qt::TreeWidgetItem([$filename, $st->size(), scalar(localtime($st->mtime()))], Qt::TreeWidgetItem::Type()));
+    }
+
+    return;
+}
+
+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",]);
+    this->_populate_tree_with_files();
+
+    return;
+}
+
+1;

App-Qt-AdHocFileManager/lib/App/Qt/AdHocFileManager/Window.pm

 use QtCore4::isa qw( Qt::MainWindow );
 use QtCore4::slots update => [], windowExit => [];
 
+use App::Qt::AdHocFileManager::FileBrowserWidget;
+
 sub addendLineEdit() {
     return this->{addendLineEdit};
 }
     );
 }
 
-sub _populate_tree_with_files
-{
-    my ($files_tree, $dir_pathname) = @_;
-
-    my $dh;
-    opendir $dh, $dir_pathname;
-
-    my @entries = sort (File::Spec->no_upwards(readdir($dh)));
-
-    closedir ($dh);
-
-    foreach my $filename (@entries)
-    {
-        my $st = stat( File::Spec->catfile($dir_pathname, $filename) );
-        $files_tree->addTopLevelItem(Qt::TreeWidgetItem([$filename, $st->size(), scalar(localtime($st->mtime()))], Qt::TreeWidgetItem::Type()));
-    }
-
-    return;
-}
 
 
 sub windowExit() {
 
     foreach my $dir_pathname (@ARGV)
     {
-        my $files_tree = Qt::TreeWidget();
-
-        $files_tree->setHeaderLabels(["Name", "Size", "Date Modified",]);
-
-        this->_populate_tree_with_files($files_tree, $dir_pathname);
-
-        $tab_widget->addTab($files_tree, $dir_pathname);
+        $tab_widget->addTab(
+            App::Qt::AdHocFileManager::FileBrowserWidget(
+                this,
+                {
+                    dir_pathname => $dir_pathname,
+                }
+            ),
+            $dir_pathname,
+        );
     }
 
     $layout->addWidget($tab_widget, 2, 0, 1, 3);