[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    KFile plugin problem !!
From:       Mario <tweakBSD () gmx ! net>
Date:       2004-07-12 12:43:19
Message-ID: 200407121443.19150.tweakBSD () gmx ! net
[Download RAW message or body]

Ok I have problems wiht my Kfile plugin for displaying Meta-Info for FreeBSD 
*.tbz packages, it behaves strange when I open a dir containing 2 or more
packages. I do a right click on packag1.tbz and view  the Meta-Info but there 
isn't any, I reload konqueror and now it works but it now shows info for 
package1.tbz on package2.tbz, info for package2.tbz on package3.tbz and so 
on.

Here is my source code, where is the problem please help me

// My header file
#ifndef __tweakBSD_pkg_H
#define __tweakBSD_pkg_H

#include <kfilemetainfo.h>
#include <qprocess.h>


class QTextView;
class QString;

class tweakBSDpkgPlugin: public KFilePlugin
{
    Q_OBJECT

public:
    tweakBSDpkgPlugin(QObject *parent, const char *name, const QStringList& 
args);
    virtual bool readInfo(KFileMetaInfo& info, uint what);
    QTextView *output;
    QProcess *proc;
public slots:
    void readfrom_pkginfo();
private:
    QString getComment();
    QString getDescription();
    QString getFiles();
};

#endif

// Next the implementation

#include "tweakBSD_pkg.h"

#include <kgenericfactory.h>
#include <kdebug.h>

#include <qfile.h>
#include <qstring.h>
#include <qtextview.h>
#include <kmessagebox.h>
#include <qregexp.h>

typedef KGenericFactory<tweakBSDpkgPlugin> tweakBSDpkgFactory;

K_EXPORT_COMPONENT_FACTORY(tweakBSD_pkg, tweakBSDpkgFactory("tweakBSD_pkg"))

tweakBSDpkgPlugin::tweakBSDpkgPlugin(QObject *parent, const char *name,
        const QStringList &args) : KFilePlugin(parent, name, args)
{
    
         output = new QTextView(0, "textview");
        proc = new QProcess( 0 );

    KFileMimeTypeInfo* info = addMimeTypeInfo("application/pkg");

    KFileMimeTypeInfo::GroupInfo* group =
            addGroupInfo(info, "General", i18n("General"));

    KFileMimeTypeInfo::ItemInfo* item;
    item = addItemInfo(group, "Name", i18n("Name"), QVariant::String);
    setAttributes(item, KFileMimeTypeInfo::MultiLine);
    item = addItemInfo(group, "Comment", i18n("Comment"), QVariant::String);
    setAttributes(item, KFileMimeTypeInfo::MultiLine);
    item = addItemInfo(group, "Description", i18n("Description"), 
QVariant::String);
    setAttributes(item, KFileMimeTypeInfo::MultiLine );
    item = addItemInfo(group, "Files", i18n("Files"), QVariant::String);
    setAttributes(item, KFileMimeTypeInfo::MultiLine);
}



void tweakBSDpkgPlugin::readfrom_pkginfo() {


output->append( proc->readStdout() );

}


QString tweakBSDpkgPlugin::getFiles() {

QRegExp rx( "*Files:\n", false, true );
QRegExp rx2( "THEEND", false, true );


QString out = output->text();
out.append( "THEEND" );
int j = out.find(rx2);


QString str = out.left( j );
str.replace(rx, "");
str.replace("\n\n", "");
return str;

}

QString tweakBSDpkgPlugin::getComment() {


      
QRegExp rx( "Information*Comment:\n", false, true );
QRegExp rx2( "Description:", false, true );


QString out = output->text();
int j = out.find(rx2);


QString str = out.left( j );
str.replace(rx, "");
str.replace("\n\n", "");
return str;

}

QString tweakBSDpkgPlugin::getDescription() {

     
                         
QRegExp rx( "*Description:\n", false, true );
QRegExp rx2( "Files:", false, true );


QString out = output->text();
int j = out.find(rx2);


QString str = out.left( j );
str.replace(rx, "");
str.replace("\n\n", "");
return str;

}


bool tweakBSDpkgPlugin::readInfo(KFileMetaInfo& info, uint)
{
         
       proc->addArgument( "pkg_info" );
      proc->addArgument( "-cdL" );
       proc->addArgument( info.path() );
        connect( proc, SIGNAL(readyReadStdout()),
                this, SLOT(readfrom_pkginfo()) );
      proc->start();    

    
    KFileMetaInfoGroup group = appendGroup(info, "General");
     appendItem(group, "Name", info.path() );
      appendItem(group, "Comment", getComment() );
       appendItem(group, "Description", getDescription() ); 
        appendItem(group, "Files", getFiles());

    return true;
}

#include "tweakBSD_pkg.moc"
 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic