Seite 1 von 1
Ort des Plugins
Verfasst: 17. September 2009 14:55
von AuE
Hi,
ich würde gerne wissen ob man zur Laufzeit den Ort eines geladenen Plugins (im Plugin selbst) herausfinden kann?!??
Verfasst: 17. September 2009 15:51
von NoRulez
Du gibst ja selbst an wo die Plugins liegen oder?
LG NoRulez
Verfasst: 17. September 2009 16:06
von AuE
Naja...
ich lade die Plugins. Später weiß habe ich nur ein Object vom TypMainInterface der auf alle geladenen Plugins passt. D.h. wenn ich durch meine Objekte laufe sehe ich nur MainInterface Typen => dieser kann von TypA, TypB, TypC sein da alle von diesem Interface abgeleitet sind.
Sprich ich weiß nach dem Laden nichts mehr vom Objek-es ist ein anonymer Typ quasi.
Verfasst: 17. September 2009 16:36
von upsala
Dann mußt du halt die Information zum Zeitpunkt des Ladens mitablegen.
Verfasst: 18. September 2009 08:18
von NoRulez
Also wie schon upsala sagte, entweder die Informationen mitspeichern.
Oder aber - so habe ich es gemacht - wenn Du Zugriff darauf hast, eine abstrakte Klasse bsp. AdditionalPluginDataInterface die TypMainInterface erbt und somit zusätzliche Daten in den Plugins befüllen.
Oder Du speicherst die Informationen mit, àla:
bzw.
Code: Alles auswählen
struct AdditionalData {
QString pluginPath;
};
QMap<TypMainInterface*, AdditionalData> pluginInfo;
LG NoRulez
Verfasst: 18. September 2009 08:53
von AuE
Hi,
habs wie folgt gelöst (noch unsauber - die QOBJECT Klasse bekommt noch nen eigenes File)
Code: Alles auswählen
class ContolCenterMain;
class Internalisation : public QObject
{
Q_OBJECT
public:
Internalisation():isInitializedPath(false), isInitializedName(false),pluginPath(QString()),pluginName(QString()){}
void setPluginPath(const QString &path){ if(!isInitializedPath) {pluginPath = path; isInitializedPath =true;}}
void setPluginName(const QString &name){ if(!isInitializedName) {pluginName = name; isInitializedName =true;}}
public slots: // TODO: Move away from here!!
void on_languagChange(const QString &langSuffix)
{
if (pluginPath.isEmpty() || pluginName.isEmpty())
{
qDebug ()<< "Name or path for plugin not set. Maybe forgot to call setName/path after creating the Plugin?";
return;
}
qDebug() <<pluginPath.left(pluginPath.lastIndexOf(QDir::separator())+1) + "translations/"+ pluginName + langSuffix +".qm";
QString tranFile = pluginPath.left(pluginPath.lastIndexOf(QDir::separator())+1) + "translations/"+ pluginName + langSuffix + ".qm";
if (QFile::exists(tranFile))
{
QTranslator tran;
if (tran.load(tranFile))
{
qApp->installTranslator(&tran);
}
else
{
qDebug() << "The translation file could be found but couldn't be loaded!";
}
}
else
{
qDebug() << "Sorry the translation file for this language couldn't be found <<" << tranFile <<">>";
}
}
private:
bool isInitializedPath;
bool isInitializedName;
QString pluginPath;
QString pluginName;
};
class AV_Plugin_Interface
{
friend class ContolCenterMain;
public:
virtual ~AV_Plugin_Interface() {}
virtual QWidget *createWidget(QWidget *parent) = 0; // must implement
virtual QString getName() = 0; // must implement
virtual QIcon getIconForWdg() = 0; // must implement
virtual QMenu *getMenuSystemTray() = 0;// must implement
virtual QMenu *getMenuMenuBar() = 0;// must implement
// IMPLEMENT THE FOLLOWING AS PUBLIC SLOTS IN THE CLASS!!!!!
protected:
Internalisation internalizer;
};