|
|
|
@ -20,25 +20,24 @@ |
|
|
|
|
|
|
|
|
|
#include <gtk/gtk.h> |
|
|
|
|
#include "keepassx-gnome.h" |
|
|
|
|
#define CSTRING(x)(x.toUtf8().data()) |
|
|
|
|
#define CSTR(x)(x.toUtf8().data()) |
|
|
|
|
|
|
|
|
|
Q_EXPORT_PLUGIN2(keepassx_gnome, GnomePlugin) |
|
|
|
|
|
|
|
|
|
QString GnomePlugin::openExistingFileDialog(QWidget* parent,QString title,QString dir, |
|
|
|
|
QStringList Filters){ |
|
|
|
|
|
|
|
|
|
QString GnomePlugin::openExistingFileDialog(QWidget* parent,QString title,QString dir,QStringList Filters){ |
|
|
|
|
unsigned int NumFilters=Filters.size(); |
|
|
|
|
GtkWidget *FileDlg; |
|
|
|
|
QString filename; |
|
|
|
|
gtk_init(0,0); |
|
|
|
|
FileDlg=gtk_file_chooser_dialog_new(title.toUtf8().data(),NULL, |
|
|
|
|
FileDlg=gtk_file_chooser_dialog_new(CSTR(title),NULL, |
|
|
|
|
GTK_FILE_CHOOSER_ACTION_OPEN, |
|
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
|
|
|
|
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, |
|
|
|
|
NULL); |
|
|
|
|
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(FileDlg),dir.toUtf8().data()); |
|
|
|
|
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(FileDlg),CSTR(dir)); |
|
|
|
|
GtkFileFilter** filters=parseFilterStrings(Filters); |
|
|
|
|
|
|
|
|
|
for(int i=0;i<Filters.size();i++){
|
|
|
|
|
for(int i=0;i<NumFilters;i++){
|
|
|
|
|
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(FileDlg),filters[i]); |
|
|
|
|
} |
|
|
|
|
if (gtk_dialog_run(GTK_DIALOG(FileDlg)) == GTK_RESPONSE_ACCEPT){ |
|
|
|
@ -46,13 +45,13 @@ QString GnomePlugin::openExistingFileDialog(QWidget* parent,QString title,QStrin |
|
|
|
|
filename = QString::fromUtf8(filename_cstring); |
|
|
|
|
g_free(filename_cstring); |
|
|
|
|
}
|
|
|
|
|
gtk_widget_destroy (FileDlg); |
|
|
|
|
gtk_widget_destroy(FileDlg); |
|
|
|
|
return filename; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
GtkFileFilter** GnomePlugin::parseFilterStrings(const QStringList& filters){ |
|
|
|
|
if(!filters.size())return NULL; |
|
|
|
|
GtkFileFilter **f=new GtkFileFilter*[filters.size()]; |
|
|
|
|
GtkFileFilter **f=g_new(GtkFileFilter*,filters.size()); |
|
|
|
|
for(int i=0;i<filters.size();i++){ |
|
|
|
|
f[i]=gtk_file_filter_new(); |
|
|
|
|
QString name; |
|
|
|
@ -63,12 +62,13 @@ GtkFileFilter** GnomePlugin::parseFilterStrings(const QStringList& filters){ |
|
|
|
|
else |
|
|
|
|
break;
|
|
|
|
|
} |
|
|
|
|
gtk_file_filter_set_name(f[i],CSTRING(name)); |
|
|
|
|
gtk_file_filter_set_name(f[i],CSTR(name)); |
|
|
|
|
p++; |
|
|
|
|
QString pattern; |
|
|
|
|
for(p;p<filters[i].size()-1;p++){ |
|
|
|
|
if(filters[i][p]==' '){ |
|
|
|
|
gtk_file_filter_add_pattern(f[i],CSTRING(pattern)); |
|
|
|
|
for(p;p<filters[i].size();p++){ |
|
|
|
|
if(filters[i][p]==' ' || filters[i][p]==')'){ |
|
|
|
|
gtk_file_filter_add_pattern(f[i],CSTR(pattern)); |
|
|
|
|
qDebug(CSTR(pattern)); |
|
|
|
|
pattern=QString(); |
|
|
|
|
} |
|
|
|
|
else{ |
|
|
|
@ -80,4 +80,34 @@ GtkFileFilter** GnomePlugin::parseFilterStrings(const QStringList& filters){ |
|
|
|
|
return f; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QString GnomePlugin::saveFileDialog(QWidget* parent,QString title,QString dir,QStringList Filters){return QString();} |
|
|
|
|
QStringList GnomePlugin::openExistingFilesDialog(QWidget* parent,QString title,QString dir,QStringList Filters){ |
|
|
|
|
unsigned int NumFilters=Filters.size(); |
|
|
|
|
GtkWidget *FileDlg; |
|
|
|
|
QStringList filenames; |
|
|
|
|
gtk_init(0,0); |
|
|
|
|
FileDlg=gtk_file_chooser_dialog_new(CSTR(title),NULL, |
|
|
|
|
GTK_FILE_CHOOSER_ACTION_OPEN, |
|
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
|
|
|
|
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, |
|
|
|
|
NULL); |
|
|
|
|
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(FileDlg),CSTR(dir)); |
|
|
|
|
gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(FileDlg),true); |
|
|
|
|
GtkFileFilter** filters=parseFilterStrings(Filters); |
|
|
|
|
|
|
|
|
|
for(int i=0;i<NumFilters;i++){
|
|
|
|
|
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(FileDlg),filters[i]); |
|
|
|
|
} |
|
|
|
|
if (gtk_dialog_run(GTK_DIALOG(FileDlg)) == GTK_RESPONSE_ACCEPT){ |
|
|
|
|
GSList* FilenameList=gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(FileDlg)); |
|
|
|
|
GSList* front=FilenameList; |
|
|
|
|
while(FilenameList!=0){ |
|
|
|
|
filenames << QString::fromUtf8((char*)FilenameList->data); |
|
|
|
|
FilenameList=FilenameList->next; |
|
|
|
|
} |
|
|
|
|
g_slist_free(front); |
|
|
|
|
}
|
|
|
|
|
gtk_widget_destroy(FileDlg); |
|
|
|
|
return filenames; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QString GnomePlugin::saveFileDialog(QWidget* parent,QString title,QString dir,QStringList Filters,bool OverWriteWarn){return QString();} |