/***************************************************************************
kappldialog.cpp - Source file of class KApplDialog
This is the Dialog for all applications found in the
KDE directories
-----------------------------------------------------------------------
begin : Thu Mar 18 1999
copyright : (C) 1999 by Geri House
email : ge_ha@yahoo.com
***************************************************************************/
/***************************************************************************
* *
* 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 <qdir.h>
#include <qfileinfo.h>
#include <qstring.h>
#include <qpixmap.h>
#include <qcursor.h>
#include <qlabel.h>
#include <qtooltip.h>
#include <qheader.h>
#include <qfiledialog.h>
#include <kapp.h>
#include <kmsgbox.h>
#include <kiconloader.h>
#include <ksimpleconfig.h>
#include "kappldialog.h"
KApplDialog::KApplDialog(QWidget * parent, const char * name, bool modal)
:QDialog(parent,name,modal) {
QString str=kapp->kde_appsdir();
resize(220,350);
QLabel *label1 = new QLabel(this, "Label");
label1->setGeometry(10,10,200,25);
label1->setText(i18n("Select a KDE Application:"));
listBox = new QListView(this, "listBox");
listBox->addColumn( i18n("Name") );
listBox->setColumnWidthMode(0,QListView::Maximum);
listBox->header()->hide();
insertApplications(str);
QToolTip::add(listBox, i18n("Overtake an application with double clicking"));
backBtn = new QPushButton(this, "back");
backBtn->setPixmap(kapp->getIconLoader()->loadIcon("back.xpm"));
QToolTip::add(backBtn, i18n("Go back to Application"));
forwardBtn = new QPushButton(this, "forward");
forwardBtn->setPixmap(kapp->getIconLoader()->loadIcon("forward.xpm"));
QToolTip::add(forwardBtn, i18n("Not found in the List ?"));
connect(backBtn,SIGNAL(clicked()), this, SLOT(closeWithSelection()));
connect(forwardBtn,SIGNAL(clicked()), this, SLOT(openFileDialog()));
connect(listBox,SIGNAL(doubleClicked ( QListViewItem *)), this, SLOT(closeWithSelection()));
}
KApplDialog::~KApplDialog(){
}
void KApplDialog::closeWithSelection() {
QListViewItem *item=listBox->currentItem();
if (item!=0) {
QString str= item->text(0);
str.remove(0,1); //remove trailing blank
emit setApplName((const char*)str);
accept();
}
else
reject();
}
void KApplDialog::insertApplications(QString str) {
QDir dir(str);
if (dir.exists()) {
dir.setFilter(QDir::Dirs | QDir::Files);
const QFileInfoList *strList = dir.entryInfoList();
QFileInfo *f=strList->first();
while (f!=0) {
if (f->fileName()!="." && f->fileName()!="..") {
if (f->extension()=="kdelnk") {
KSimpleConfig kconfig(f->absFilePath(), true);
kconfig.setGroup("KDE Desktop Entry");
QString tmpStr(" ");
tmpStr+=(const char*)f->baseName();
QListViewItem * newItem= new QListViewItem(listBox,tmpStr);
QString pixStr = kconfig.readEntry("MiniIcon");
QPixmap pix;
if (pixStr.isEmpty()==FALSE) {
pix=kapp->getIconLoader()->loadApplicationMiniIcon(pixStr);
}
else {
pixStr = kconfig.readEntry("Icon");
if (pixStr.isEmpty()==FALSE) {
pix=kapp->getIconLoader()->loadIcon(pixStr);
pix.resize(16,16);
}
else
pix=kapp->getIconLoader()->loadApplicationMiniIcon("unknown.xpm");
}
newItem->setPixmap(0,pix);
}
if (f->isDir()==TRUE)
insertApplications(f->absFilePath());
}
f=strList->next();
}
}
}
void KApplDialog::resizeEvent ( QResizeEvent * e) {
listBox->setGeometry(10,40,width()-20,height()-100);
backBtn->setGeometry(10,height()-40,26,26);
forwardBtn->setGeometry(width()-36,height()-40,26,26);
QDialog::resizeEvent(e);
}
void KApplDialog::openFileDialog() {
QFileInfo f;
QString str;
do {
str=QFileDialog::getOpenFileName ( 0, 0, this, "Get Application" );
if (str.isNull()==FALSE) {
f.setFile(str);
if (f.isExecutable()==FALSE) {
KMsgBox::message(this, i18n("Selection error"),
i18n("Your selected file isn't an Executable!"),
KMsgBox::EXCLAMATION);
}
}
else
break;
} while (f.exists()==FALSE || f.isExecutable()==FALSE);
if (str.isNull()==FALSE) {
emit setApplName((const char*)f.fileName());
accept();
}
}
Documentation generated by haeusler@stiegl on Fri Apr 16 09:31:32 MET DST 1999