#include <QtGui>
//#include <QDebug>
Q_OBJECT
public:
signals:
void currentDir(const QString&);
protected slots:
};
clear();
if (arg.size() == 2) dir.setCurrent(arg.at(1));
dir.
setFilter(QDir::AllEntries |
QDir::Hidden |
QDir::System);
dir.
setSorting(QDir::DirsFirst |
QDir::IgnoreCase |
QDir::Name);
list = dir.entryList();
for (int i = 0; i < list.size(); ++i) {
insertItem(i, list.at(i));
}
dir = dir.canonicalPath();
if (dir.isRoot()) {
//QFileInfoList roots = QDir::drives();
QList<QFileInfo> roots
= QDir::drives();
string.truncate(3);
int n = 0;
for (int i = 0; i < roots.size(); ++i) {
if (info.absoluteFilePath() != string) {
insertItem(n, info.absoluteFilePath());
++n;
}
}
} else takeItem(0);
};
int flag = 0;
QString ext
= fiche.
suffix().
toLower();
ext1 << "" << "txt" << "bak" <<"bat" <<"ini" <<"log" << "dat" << "sys";
ext2 <<"h"<<"cpp"<<"pro"<<"lsp"<<"frm"<<"java"<<"vb"<<"bas"<<"js"<<"awk"<<"xul";
if (fiche.isDir()) {
clear();
dir.setCurrent(str);
emit currentDir(dir.currentPath());
dir.
setFilter(QDir::AllEntries |
QDir::Hidden |
QDir::System);
dir.
setSorting(QDir::DirsFirst |
QDir::IgnoreCase |
QDir::Name);
list = dir.entryList();
for (int i = 0; i < list.size(); ++i) {
insertItem(i, list.at(i));
}
dir = dir.canonicalPath();
if (dir.isRoot()) {
clear();
dir.
setFilter(QDir::AllEntries |
QDir::Hidden |
QDir::System);
dir.
setSorting(QDir::DirsFirst |
QDir::IgnoreCase|
QDir::Name);
list = dir.entryList();
for (int i = 0; i < list.size(); ++i) {
insertItem(i, list.at(i));
}
//QFileInfoList roots = QDir::drives();
QList<QFileInfo> roots
= QDir::drives();
string.truncate(3);
int n = 0;
for (int i = 0; i < roots.size(); ++i) {
if (info.absoluteFilePath() != string) {
insertItem(n, info.absoluteFilePath());
++n;
}
}
} else takeItem(0);
} else {
emit currentDir(dir.currentPath());
if (ext1.contains(ext)) flag = 1;
if (ext2.contains(ext)) flag = 2;
switch(flag) {
case 1: QProcess::startDetached(cmd.
append(str
));
break;
}
}
};
// --------------------
Q_OBJECT
public:
signals:
void setDir(const QString&);
protected slots:
void onReturnPressed();
};
setText
(QDir::currentPath());
connect( this, SIGNAL(returnPressed()), this, SLOT(onReturnPressed()));
};
void CLineEdit::onReturnPressed() {
dir.setCurrent(string);
emit setDir(dir.currentPath());
//qDebug() << QDir::currentPath();
};
// --------------------
int main(int argc, char *argv[]) {
CListBox lbox(&wnd);
CLineEdit ledit(&wnd);
layout.addWidget(&lbox, Qt::AlignHCenter | Qt::AlignVCenter);
layout.addWidget(&ledit, Qt::AlignHCenter | Qt::AlignVCenter);
wnd.setWindowTitle("File browser");
wnd.show();
lbox.setFocus();
lbox.setPalette(p1);
ledit.setPalette(p2);
QObject::connect(&lbox,
SIGNAL(currentDir
(const QString
&)),
&ledit,
SLOT(setText
(const QString
&)));
QObject::connect(&ledit,
SIGNAL(setDir
(const QString
&)),
&lbox,
SLOT(update
()));
return app.exec();
}
#include "main.moc"
#include <QtGui>
//#include <QDebug>
class CListBox: public QListWidget {
Q_OBJECT
public:
CListBox(QWidget *pParent);
signals:
void currentDir(const QString&);
protected slots:
void onActivation(QListWidgetItem *item);
};
CListBox::CListBox(QWidget *pParent): QListWidget(pParent) {
clear();
QDir dir;
QStringList list;
QStringList arg = QCoreApplication::arguments();
if (arg.size() == 2) dir.setCurrent(arg.at(1));
dir.setFilter(QDir::AllEntries | QDir::Hidden | QDir::System);
dir.setSorting(QDir::DirsFirst | QDir::IgnoreCase | QDir::Name);
list = dir.entryList();
for (int i = 0; i < list.size(); ++i) {
insertItem(i, list.at(i));
}
dir = dir.canonicalPath();
if (dir.isRoot()) {
//QFileInfoList roots = QDir::drives();
QList<QFileInfo> roots = QDir::drives();
QString string = QDir::currentPath();
string.truncate(3);
int n = 0;
for (int i = 0; i < roots.size(); ++i) {
QFileInfo info = roots.at(i);
if (info.absoluteFilePath() != string) {
insertItem(n, info.absoluteFilePath());
++n;
}
}
} else takeItem(0);
connect(this, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(onActivation(QListWidgetItem*)));
};
void CListBox::onActivation(QListWidgetItem *item) {
QDir dir;
int flag = 0;
QStringList list;
QString str = item->text();
QFileInfo fiche(str);
QString ext = fiche.suffix().toLower();
QStringList ext1, ext2;
ext1 << "" << "txt" << "bak" <<"bat" <<"ini" <<"log" << "dat" << "sys";
ext2 <<"h"<<"cpp"<<"pro"<<"lsp"<<"frm"<<"java"<<"vb"<<"bas"<<"js"<<"awk"<<"xul";
if (fiche.isDir()) {
clear();
dir.setCurrent(str);
emit currentDir(dir.currentPath());
dir.setFilter(QDir::AllEntries | QDir::Hidden | QDir::System);
dir.setSorting(QDir::DirsFirst | QDir::IgnoreCase | QDir::Name);
list = dir.entryList();
for (int i = 0; i < list.size(); ++i) {
insertItem(i, list.at(i));
}
dir = dir.canonicalPath();
if (dir.isRoot()) {
clear();
dir.setFilter(QDir::AllEntries | QDir::Hidden | QDir::System);
dir.setSorting(QDir::DirsFirst | QDir::IgnoreCase| QDir::Name);
list = dir.entryList();
for (int i = 0; i < list.size(); ++i) {
insertItem(i, list.at(i));
}
//QFileInfoList roots = QDir::drives();
QList<QFileInfo> roots = QDir::drives();
QString string = QDir::currentPath();
string.truncate(3);
int n = 0;
for (int i = 0; i < roots.size(); ++i) {
QFileInfo info = roots.at(i);
if (info.absoluteFilePath() != string) {
insertItem(n, info.absoluteFilePath());
++n;
}
}
} else takeItem(0);
} else {
emit currentDir(dir.currentPath());
QString cmd = "c:/dos/ed /p ";
if (ext1.contains(ext)) flag = 1;
if (ext2.contains(ext)) flag = 2;
switch(flag) {
case 1: QProcess::startDetached(cmd.append(str)); break;
case 2: QProcess::startDetached("led", QStringList() << str); break;
default: QProcess::startDetached("start", QStringList() << str);
}
}
};
// --------------------
class CLineEdit: public QLineEdit {
Q_OBJECT
public:
CLineEdit(QWidget *pParent);
signals:
void setDir(const QString&);
protected slots:
void onReturnPressed();
};
CLineEdit::CLineEdit(QWidget *pParent): QLineEdit(pParent) {
setText(QDir::currentPath());
connect( this, SIGNAL(returnPressed()), this, SLOT(onReturnPressed()));
};
void CLineEdit::onReturnPressed() {
QDir dir;
QString string = displayText();
dir.setCurrent(string);
emit setDir(dir.currentPath());
//qDebug() << QDir::currentPath();
};
// --------------------
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QFrame wnd;
QVBoxLayout layout(&wnd);
CListBox lbox(&wnd);
CLineEdit ledit(&wnd);
layout.addWidget(&lbox, Qt::AlignHCenter | Qt::AlignVCenter);
layout.addWidget(&ledit, Qt::AlignHCenter | Qt::AlignVCenter);
wnd.setWindowTitle("File browser");
wnd.show();
lbox.setFocus();
QPalette p1 = lbox.palette();
p1.setColor(QPalette::Base, QColor(255, 248, 220));
lbox.setPalette(p1);
QPalette p2 = ledit.palette();
p2.setColor(QPalette::Base, QColor(255, 248, 220));
ledit.setPalette(p2);
QObject::connect(&lbox, SIGNAL(currentDir(const QString&)), &ledit, SLOT(setText(const QString&)));
QObject::connect(&ledit, SIGNAL(setDir(const QString&)), &lbox, SLOT(update()));
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks