Added images/files browser.
authorCuong Le <metacuong@gmail.com>
Sun, 28 Aug 2011 08:25:08 +0000 (15:25 +0700)
committerCuong Le <metacuong@gmail.com>
Sun, 28 Aug 2011 08:25:08 +0000 (15:25 +0700)
What should i do with that ?!

controller.cpp
controller.h
qml/LichViet/FileBrowser.qml
qml/LichViet/MenuScreen.qml
qml/LichViet/main.qml

index 209e0f8..a2ecef5 100644 (file)
@@ -18,6 +18,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>
 #include "controller.h"
 
 #include <QDir>
 #include "controller.h"
 
 #include <QDir>
+#include <QDebug>
 
 Controller::Controller(QObject *parent) :
     QObject(parent)
 
 Controller::Controller(QObject *parent) :
     QObject(parent)
@@ -30,4 +31,22 @@ bool Controller::pathExists(const QString &path) {
     return dir.exists();
 }
 
     return dir.exists();
 }
 
+QStringList Controller::getImages(const QString &path) const{
+    QDir dir(path);
+    QStringList filters;
+    filters << "*.png" << "*.jpg" << "*.jpeg";
+    dir.setNameFilters(filters);
+
+    QStringList m_images;
+
+    dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
+    dir.setSorting(QDir::Size | QDir::Reversed);
+    QFileInfoList list = dir.entryInfoList();
+    for (int i = 0; i < list.size(); ++i) {
+        QFileInfo fileInfo = list.at(i);
+        m_images.append(fileInfo.absoluteFilePath());
+    }
+
+    return m_images;
+}
 
 
index 9c3629c..2f70a12 100644 (file)
@@ -19,10 +19,12 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>
 #define CONTROLLER_H
 
 #include <QObject>
 #define CONTROLLER_H
 
 #include <QObject>
+#include <QStringList>
 
 class Controller : public QObject
 {
     Q_OBJECT
 
 class Controller : public QObject
 {
     Q_OBJECT
+
 public:
     explicit Controller(QObject *parent = 0);
 
 public:
     explicit Controller(QObject *parent = 0);
 
@@ -30,6 +32,7 @@ signals:
 
 public slots:
     bool pathExists(const QString &path);
 
 public slots:
     bool pathExists(const QString &path);
+    QStringList getImages(const QString &path) const;
 };
 
 #endif // CONTROLLER_H
 };
 
 #endif // CONTROLLER_H
index f67bf63..4d78ec7 100644 (file)
@@ -25,6 +25,28 @@ Rectangle {
     visible: true
     opacity:0.9
     color:"white"
     visible: true
     opacity:0.9
     color:"white"
+
+    ListModel{
+        id:img
+
+        function list(){
+            while(img.count>0) img.remove(img.count-1);
+            var limg = Controller.getImages("/home/cuongle");
+            for (var i=0;i<limg.length;i++)
+                append({name:limg[i]})
+        }
+    }
+
+    GridView {
+        anchors.fill: parent;anchors.topMargin: 35;anchors.leftMargin: 5;anchors.rightMargin: 5;anchors.bottomMargin: 12
+        model: img
+        delegate: Column {
+            Image { source:  "file:"+name; anchors.horizontalCenter: parent.horizontalCenter; width:100;height:100; }
+            Text { text: "-"; anchors.horizontalCenter: parent.horizontalCenter }
+        }
+    }
+
+
 }
 
 ToolBar { id: toolBar; height: 50;
 }
 
 ToolBar { id: toolBar; height: 50;
@@ -41,4 +63,8 @@ ToolBar { id: toolBar; height: 50;
     }
 }
 
     }
 }
 
+function refresh(){
+    img.list();
+}
+
 }
 }
index c654e55..26f6a29 100644 (file)
@@ -60,12 +60,12 @@ Item{
                  ListElement {
                      idm:5; name: "Xem Theo Tháng";title:"Xem ngày Dương Lịch/Âm Lịch dưới dạng tháng"
                  }
                  ListElement {
                      idm:5; name: "Xem Theo Tháng";title:"Xem ngày Dương Lịch/Âm Lịch dưới dạng tháng"
                  }
-                 ListElement {
+               /*  ListElement {
                     idm:7; name: "Đổi Theme";title:"Thay đổi theme, hình nền, ..."
                  }
                  ListElement {
                     idm:8; name: "Đổi Hình Nền";title:"/opt/bar/load.jpg"
                     idm:7; name: "Đổi Theme";title:"Thay đổi theme, hình nền, ..."
                  }
                  ListElement {
                     idm:8; name: "Đổi Hình Nền";title:"/opt/bar/load.jpg"
-                 }
+                 }*/
                  ListElement {
                      idm:6; name: "Giới Thiệu";title:"..."
                  }
                  ListElement {
                      idm:6; name: "Giới Thiệu";title:"..."
                  }
index 338f9a1..805f0a0 100644 (file)
@@ -382,6 +382,11 @@ Item {
                  PropertyChanges { target: fileBrowser; x: 0; focus:true; visible:true;}
                  PropertyChanges { target: toolBar; y: screen.height }
                  PropertyChanges { target: toolBar }
                  PropertyChanges { target: fileBrowser; x: 0; focus:true; visible:true;}
                  PropertyChanges { target: toolBar; y: screen.height }
                  PropertyChanges { target: toolBar }
+                 StateChangeScript {
+                     script:{
+                         fileBrowser.refresh();
+                     }
+                    }
              },
          State {
              name: "optionsscreen";
              },
          State {
              name: "optionsscreen";