-
Notifications
You must be signed in to change notification settings - Fork 1
/
home.cpp
135 lines (103 loc) · 3.41 KB
/
home.cpp
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
#include "home.h"
#include "ui_home.h"
#include "qsettings.h"
#include <qdir.h>
#include <qfileinfo.h>
#include "osso-intl.h"
#include <QDesktopWidget>
QString hPath;
QIcon ich;
QSettings hsettings("worldclock", "filemanager");
QSettings hfoldericons("worldclock", "filemanager_folders");
QSettings hfileicons("worldclock", "filemanager_icons");
Home::Home(QWidget *parent, QString path) :
QDialog(parent),
ui(new Ui::Home)
{
ui->setupUi(this);
selected = "";
this->setWindowTitle(_("cloc_ti_open_sound_clip"));
ui->folderButton_up->setIcon( QIcon::fromTheme("filemanager_folder_up") );
QFileInfo dr(path);
ui->folderbutton->setIcon( QIcon::fromTheme("general_folder") );
ui->folderbutton->setText( dr.fileName() );
if ( path == "/") ui->folderbutton->setText( "/" );
ui->folderbutton->setValueText( path );
if ( path == "/") ui->folderbutton->setValueText( "" );
CargarBrowser( path );
setAttribute(Qt::WA_Maemo5AutoOrientation, true);
}
Home::~Home()
{
delete ui;
}
void Home::CargarBrowser(QString directorio)
{
hPath = directorio;
QDir dir ( directorio, "*" );
dir.setFilter ( QDir::Dirs | QDir::Hidden );
if ( !dir.isReadable() )
return;
ui->folderbutton->setText( QFileInfo(directorio).fileName() );
if ( directorio == "/") ui->folderbutton->setText( "/" );
ui->folderbutton->setValueText( directorio );
if ( directorio == "/") ui->folderbutton->setValueText( "" );
ui->listWidget->clear();
dir.setFilter( QDir::AllEntries | QDir::Hidden | QDir::NoDotAndDotDot );
dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::IgnoreCase );
QRegExp fileExt( "\\.ogg$|\\.mp3$|\\.aac$" );
QFileInfoList list = dir.entryInfoList();
for (int i = 0; i < list.size(); ++i)
{
QFileInfo fileInfo = list.at(i);
if ( fileInfo.isDir() )
{
QListWidgetItem *item1 = new QListWidgetItem( ui->listWidget );
item1->setText(fileInfo.fileName());
item1->setIcon(QIcon::fromTheme("general_folder"));
ui->listWidget->insertItem( i, item1 );
}
else if (fileInfo.fileName().toLower().contains(fileExt))
{
QListWidgetItem *item1 = new QListWidgetItem( ui->listWidget );
item1->setText(fileInfo.fileName());
item1->setIcon(QIcon::fromTheme("general_audio_file"));
ui->listWidget->insertItem( i, item1 );
}
}
connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(orientationChanged()));
if ( ui->listWidget->count() > 0 ) {
ui->listWidget->scrollToItem(ui->listWidget->item(0));
}
}
void Home::orientationChanged()
{
if (QApplication::desktop()->screenGeometry().width() < QApplication::desktop()->screenGeometry().height())
{
this->resize(398, 692);
}
}
void Home::on_listWidget_itemClicked(QListWidgetItem* item)
{
QString temp = hPath;
if ( temp != "/" ) temp.append("/");
temp.append( item->text() );
if ( QFileInfo(temp).isFile() )
{
selected = temp;
this->accept();
}
else if ( QFileInfo(temp).isDir() )
{
CargarBrowser( temp );
}
}
void Home::on_folderButton_up_clicked()
{
if ( hPath == "/" ) return;
QString nPath = hPath;
int i = nPath.lastIndexOf( "/" );
nPath.remove ( i, nPath.length() - i );
if ( nPath == "" ) nPath = "/";
CargarBrowser( nPath );
}