⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kfiledialog.cpp

📁 PIXIL is a small footprint operating environment, complete with PDA PIM applications, a browser and
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    if (pathstr.left(1)[0] == '/')	pathstr.insert(0, "file:");    if (dir->url() == pathstr) { // already set	return;    }    if (clearforward) {	// autodelete should remove this one	backStack.push(new QString(dir->url()));	forwardStack.clear();    }    // make a little test to avoid creating of a KURL object    // in most cases    if ( !acceptUrls && strchr(_pathstr, ':') ) {	KURL testURL(pathstr);	if ( !testURL.isLocalFile() ) {	    QMessageBox::message(i18n("Error: Not local file"),				 i18n("The specified directory is not a "				      "local directory\n"				      "But the application accepts just "				      "local files."),				 i18n("OK"), this);	    return;	}    }	    QString backup = dir->url();    dir->setPath(pathstr);    if (!dir->isReadable()) {	QMessageBox::message(i18n("Error: Cannot Open Directory"),			     i18n("The specified directory does not exist\n"				  "or was not readable."),			     i18n("Dismiss"),			     this, "kfiledlgmsg");	dir->setPath(backup);    } else {	emit dirEntered(pathstr);	updateHistory( !forwardStack.isEmpty(), !backStack.isEmpty() );	pathChanged();    }    toolbar->setItemEnabled(PARENT_BUTTON, !dir->isRoot());}void KFileBaseDialog::rereadDir(){    // some would call this dirty. I don't ;)    dir->setPath(dir->url());    pathChanged();}KFileDialog::KFileDialog(const char *dirName, const char *filter,				 QWidget *parent, const char *name,				 bool modal, bool acceptURLs)    : KFileBaseDialog(dirName, filter, parent, name, modal, acceptURLs){    init();}QString KFileDialog::getOpenFileName(const char *dir, const char *filter,				     QWidget *parent, const char *name){    QString filename;    KFileDialog *dlg= new KFileDialog(dir, filter, parent, name, true, false);    dlg->setCaption(i18n("Open"));    if (dlg->exec() == QDialog::Accepted)	filename = dlg->selectedFile();    delete dlg;    return filename;}QString KFileDialog::getSaveFileName(const char *dir, const char *filter,				     QWidget *parent, const char *name){    KFileDialog *dlg= new KFileDialog(dir, filter, parent, name, true, false);    dlg->setCaption(i18n("Save As"));    QString filename;    if (dlg->exec() == QDialog::Accepted)	filename= dlg->selectedFile();    delete dlg;    return filename;}// Protectedvoid KFileBaseDialog::pathChanged(){    debugC("changed %ld", time(0));    // Not forgetting of course the path combo box    toolbar->clearCombo(PATH_COMBO);    QString path= dir->path();    QString pos= strtok(path.data(), "/");    QStrList list;    list.insert(0, i18n("Root Directory"));    while (!(pos.isNull())) {	list.insert(0, pos+"/");	pos= strtok(0, "/");    }    toolbar->getCombo(PATH_COMBO)->insertStrList(&list);    fileList->clear();    int filter = QDir::Files | QDir::Dirs;    if (showHidden)	filter |= QDir::Hidden;    // it may be, that we weren't ready at this time    if (!finished)	QApplication::restoreOverrideCursor();    finished = false;    // when kfm emits finished, the slot will restore the cursor    QApplication::setOverrideCursor( waitCursor );    // lastDirectory is used to set the start path next time    // we select a file    *lastDirectory = dir->url();    const KFileInfoList *il = dir->entryInfoList(filter,						 QDir::Name | QDir::IgnoreCase);    if (!dir->isReadable()) {	QMessageBox::message(i18n("Error: Cannot Open Directory"),			     i18n("The specified directory does not exist "				  "or was not readable."),			     i18n("Dismiss"),			     this, "kfiledlgmsg");	if (backStack.isEmpty())	    home();	else	    back();    } else {	QString url;		if (acceptUrls)	    url = dir->url();	else	    url = dir->path();	if ((url.isEmpty()) || (url.right(1)[0] != '/'))	    url += "/";	if (visitedDirs->find(url) == -1)	    visitedDirs->inSort(url);		locationEdit->clear();	locationEdit->insertStrList(visitedDirs);	locationEdit->setCurrentItem(visitedDirs->at());	if (!selection.isNull())	    locationEdit->setText(url + selection);	insertNewFiles(il);    }}void KFileBaseDialog::insertNewFiles(const KFileInfoList *newone){    // does always repainting itself    fileList->addItemList(newone);    if ( showStatusLine )	updateStatusLine();}void KFileBaseDialog::addDirEntry(KFileInfo *entry, bool disableUpdating){    if (disableUpdating) {	repaint_files = false;	fileList->setAutoUpdate(false);    }    repaint_files |= fileList->addItem(entry);    if (disableUpdating) {	fileList->setAutoUpdate(true);	if (repaint_files)	    fileList->repaint(true);	if ( showStatusLine )	  updateStatusLine();    }}void KFileBaseDialog::slotDirEntry(KFileInfo *entry){    addDirEntry(entry, true);}void KFileBaseDialog::slotFinished(){    debugC("finished %ld", time(0));    if (!finished)	QApplication::restoreOverrideCursor();    finished = true;}void KFileBaseDialog::slotKfmError(int, const char *){    debugC("slotKfmError");    if (!finished)	QApplication::restoreOverrideCursor();    finished = true;}void KFileBaseDialog::comboActivated(int index){    KDir tmp = *dir;    for (int i= 0; i < index; i++) {	debugC("cdUp %s",tmp.url().data());	tmp.cdUp();    }    setDir(tmp.url(), true);}// Code pinched from kfm then hackedvoid KFileBaseDialog::back(){    if ( backStack.isEmpty() )	return;    QString *tmp= new QString(dir->path());    forwardStack.push( tmp );    QString *s = backStack.pop();    updateHistory( true, !backStack.isEmpty());    setDir(s->data(), false);    delete s;}// Code pinched from kfm then hackedvoid KFileBaseDialog::forward(){    if ( forwardStack.isEmpty() )	return;    QString *tmp= new QString(dir->path());    backStack.push(tmp);    QString *s = forwardStack.pop();    updateHistory( !forwardStack.isEmpty(), true);    setDir(s->data(), false);    delete s;}// SLOTvoid KFileBaseDialog::updateHistory(bool f, bool b){    emit historyUpdate(f, b);    toolbar->setItemEnabled(FORWARD_BUTTON, f);    toolbar->setItemEnabled(BACK_BUTTON, b);}void KFileBaseDialog::addToBookmarks() // SLOT{    debugC("Add to bookmarks called");    bookmarks->add(dir->url(), dir->url());    bookmarks->write();}void KFileBaseDialog::bookmarksChanged() // SLOT{  debugC("Bookmarks changed called");}void KFileBaseDialog::fillBookmarkMenu( KFileBookmark *parent, QPopupMenu *menu, int &id ){    KFileBookmark *bm;    for ( bm = parent->getChildren().first(); bm != NULL;	  bm = parent->getChildren().next() )    {	if ( bm->getType() == KFileBookmark::URL )	{	    menu->insertItem( bm->getText(), id );	    id++;	}	else	{	    QPopupMenu *subMenu = new QPopupMenu;	    menu->insertItem( bm->getText(), subMenu );	    fillBookmarkMenu( bm, subMenu, id );	}    }}void KFileBaseDialog::toolbarCallback(int i) // SLOT{    KConfig *c= kapp->getConfig();    QString oldgroup= c->group();    c->setGroup("KFileDialog Settings");    QString cmd;    switch(i) {    case BACK_BUTTON:	back();	break;    case FORWARD_BUTTON:	forward();	break;    case PARENT_BUTTON:	cdUp();	break;    case HOME_BUTTON:	home();	break;    case RELOAD_BUTTON:	rereadDir();	break;    case HOTLIST_BUTTON:	// It's done on the pressed() signal	debugC("Got pressed signal() for hot list");	//	toolbarPressedCallback(i);	break;    case MKDIR_BUTTON:	mkdir();	break;    case FIND_BUTTON: {	KShellProcess proc;	proc << c->readEntry("FindCommandPath", DefaultFindCommand); 	QString strURL( dirPath() ); 	KURL::decodeURL( strURL ); 	KURL url( strURL ); 	if( url.isLocalFile() && !url.isMalformed() ) { 	  proc << " "; 	  proc << c->readEntry(QString("FindSearchPathParameter"), ""); 	  proc << url.directory(); 	}	proc.start(KShellProcess::DontCare);	break;    }    case CONFIGURE_BUTTON: {	KFileDialogConfigureDlg conf(this, "filedlgconf");	conf.exec();	fileList->widget()->hide();	delete boxLayout; // this removes all child layouts too	boxLayout = 0;	// recreate this widget	delete fileList;        fileList = initFileList( wrapper );	initGUI(); // add them back to the layout managment	fileList->widget()->show();	resize(width(), height());	pathChanged(); // refresh now	break;    }    default:	warning("KFileDialog: Unknown toolbar button  (id number %d) pressed\n", i);    }    c->setGroup(oldgroup);}void KFileBaseDialog::cdUp(){    KURL u = dir->url().data();    u.cd("..");    setDir(u.url(), true);}void KFileBaseDialog::home(){    setDir( QDir::homeDirPath(), true);}void KFileBaseDialog::mkdir(){    // Modal widget asking the user the name of a new directory    //    QDialog *lMakeDir;    QLabel *label;    QLineEdit *ed;    QVBoxLayout *lLayout;    QPushButton *okButton, *cancelButton;    QHBoxLayout *lLayout2;    // Create widgets, and display using geometry management    //    lMakeDir = new QDialog(0,"MakeDir Dialog",true);    lLayout = new QVBoxLayout( lMakeDir, 5 );    label = new QLabel(lMakeDir);    label->setAlignment( AlignLeft | AlignVCenter );    label->setText(QString(i18n("Create new directory in: ")) + dir->path() );    label->setMinimumSize( label->sizeHint() );    ed= new QLineEdit(lMakeDir);    ed->setText( i18n("New Directory") );    ed->adjustSize();    ed->setFixedHeight( ed->height());    ed->selectAll();    connect(ed, SIGNAL(returnPressed()), lMakeDir, SLOT(accept()) );    lLayout->addWidget( label, 0);    lLayout->addSpacing( 5 );    lLayout->addWidget( ed, 0);    okButton = new QPushButton( lMakeDir, "okButton" );    okButton->adjustSize();    okButton->setText( i18n("OK") );    okButton->setFixedHeight( okButton->height() );    okButton-> setMinimumWidth( okButton->width() );    cancelButton = new QPushButton( lMakeDir, "cancelButton" );    cancelButton->setText( i18n("Cancel") );    cancelButton->adjustSize();    cancelButton->setFixedHeight( cancelButton->height() );    cancelButton->setMinimumWidth( cancelButton->width() );    connect( okButton, SIGNAL(pressed()), lMakeDir, SLOT(accept()) );    connect( cancelButton, SIGNAL(pressed()), lMakeDir, SLOT(reject()) );    lLayout2 = new QHBoxLayout( 5 );    lLayout->addSpacing( 10 );    lLayout->addLayout( lLayout2 , 0);    lLayout2->addWidget( okButton, 3);    lLayout2->addWidget( cancelButton, 3);    lLayout->activate();    // If the users presses enter (not escape) then create the dir    // and insert it into the ListBox    lMakeDir->resize( 10, 10);    ed->grabKeyboard();    if ( lMakeDir->exec() == Accepted ) {	if ( QDir(dir->path()).mkdir(ed->text()) == true ) {  // !! don't like this move it into KDir ??	    setDir( QString(dir->url()+ed->text()), true );	} else {	    /* Stephan: I don't understand, what this is meant for:	    QString tmp;	    if ( !dirnameList->contains( ed->text() )) {		tmp.sprintf(i18n("check permissions of directory < %s >"),			    dir->url().data());		QMessageBox::message(i18n("Error: could not create directory"),				     tmp,				     i18n("Dismiss"),				     this, "mkdirerrormsg");	    } else {		tmp.sprintf(i18n("directory < %s > already exists!"),			    dir->url().data());		QMessageBox::message(i18n("Error: directory already exists"),				     tmp,				     i18n("Dismiss"),				     this, "mkdirerrormsg2");	    }	    */	}    }    delete lMakeDir;}void KFileBaseDialog::toolbarPressedCallback(int i){    int id= idStart;    if (i == HOTLIST_BUTTON) {	// Build the menu on first use	if (bookmarksMenu == 0) {	    bookmarksMenu= new QPopupMenu;	    bookmarksMenu->insertItem(i18n("Add to bookmarks"), this,				      SLOT(addToBookmarks()));	    bookmarksMenu->insertSeparator();	    fillBookmarkMenu( bookmarks->getRoot(), bookmarksMenu, id );	}	QPoint p;	KToolBarButton *btn= toolbar->getButton(HOTLIST_BUTTON);	p= btn->mapToGlobal(QPoint(0, btn->height()));	bookmarksMenu->move(p);

⌨️ 快捷键说明

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