filebrowser.cpp

来自「KDE下的西门子手机管理程序」· C++ 代码 · 共 132 行

CPP
132
字号
/***************************************************************************                          filebrowser.cpp  -  description                             -------------------    begin                : Sun Feb 11 2001    copyright            : (C) 2001 by Matthias Welwarsky    email                : matze@stud.fbi.fh-darmstadt.de ***************************************************************************//*************************************************************************** *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU General Public License as published by  * *   the Free Software Foundation; either version 2 of the License, or     * *   (at your option) any later version.                                   * *                                                                         * ***************************************************************************/#include <qlayout.h>#include <qfileinfo.h>#include <qstringlist.h>#include <kdebug.h>#include <kfilereader.h>#include <kfiledetailview.h>#include <ktoolbar.h>#include <kcombobox.h>#include "filebrowser.h"FileBrowser::FileBrowser(QWidget *parent, const char *name ) : QWidget(parent,name) {	init();}FileBrowser::~FileBrowser(){	delete dirLister;}/** initialise internals */void FileBrowser::init(){	QVBoxLayout* layout = new QVBoxLayout(this);		KToolBar* toolBar = new KToolBar(this, "toolBar");		historyCombo = new KHistoryCombo(toolBar, "historyCombo");	historyCombo->setDuplicatesEnabled(false);		toolBar->insertButton(QString("up"), UpButton);	toolBar->insertButton(QString("back"), BackButton);	toolBar->insertButton(QString("forward"), ForwardButton);	toolBar->insertWidget(HistoryCombo, -1, historyCombo);	connect(toolBar, SIGNAL(clicked(int)), this, SLOT(toolBarButtonClicked(int)));	layout->add(toolBar);		fileView = new KFileDetailView(this, "fileView");	layout->add(fileView);	dirLister = new KFileReader();	dirLister->setNameFilter("*.bmp");	dirLister->setAutoUpdate(true);	dirLister->setShowingDotFiles(false);		connect(dirLister, SIGNAL(completed()), this, SLOT(updateView()));	connect(fileView, SIGNAL(executed(QListViewItem*)), this, SLOT(executed(QListViewItem*)));}/** No descriptions */void FileBrowser::executed(QListViewItem* item){	KFileListViewItem* flvi = dynamic_cast<KFileListViewItem*>(item);	if (!flvi) {		kdDebug() << "FileBrowser::executed(): selected Item is no KFileListViewItem!\n";		return;	}		// if it's a directory, dive into it.	const KFileViewItem* fvi = flvi->fileInfo();	if (!fvi->isFile()) {		// strip the "file:" from the url		setDirectory(fvi->urlString().mid(5));		return;	}		// Implement reading the file and displaying the preview	emit selected(fvi->urlString().mid(5));}/** No descriptions */void FileBrowser::setDirectory(const QString& dir){	currentDir = dir;	KURL url = currentDir.path();	dirLister->openURL(url, false);}/** set the directory where the browsing starts */void FileBrowser::setDirectory(const QDir& dir){	currentDir = dir;	KURL url = currentDir.path();	dirLister->openURL(url, false);}/** updates the view, called on directory change. */void FileBrowser::updateView() {	// clear the view first	fileView->KFileView::clear();		// now add the files	fileView->addItemList(dirLister->items());		// and update the view	fileView->updateView(true);		// finally, add the directory to the history	historyCombo->addToHistory(currentDir.path());}/** No descriptions */void FileBrowser::toolBarButtonClicked(int id) {	kdDebug() << "ToolBarButtonClicked("<<id<<")\n";		switch(id) {	case UpButton: {		if (!currentDir.cdUp())			break;		kdDebug() << "up to dir " << currentDir.path() << endl;		KURL url = currentDir.path();		dirLister->openURL(url, false);		break;	}	default:		break;	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?