|
|
@ -20,39 +20,38 @@ |
|
|
|
|
|
|
|
|
|
|
|
#include <gtk/gtk.h> |
|
|
|
#include <gtk/gtk.h> |
|
|
|
#include "keepassx-gnome.h" |
|
|
|
#include "keepassx-gnome.h" |
|
|
|
#define CSTRING(x)(x.toUtf8().data()) |
|
|
|
#define CSTR(x)(x.toUtf8().data()) |
|
|
|
|
|
|
|
|
|
|
|
Q_EXPORT_PLUGIN2(keepassx_gnome, GnomePlugin) |
|
|
|
Q_EXPORT_PLUGIN2(keepassx_gnome, GnomePlugin) |
|
|
|
|
|
|
|
|
|
|
|
QString GnomePlugin::openExistingFileDialog(QWidget* parent,QString title,QString dir, |
|
|
|
QString GnomePlugin::openExistingFileDialog(QWidget* parent,QString title,QString dir,QStringList Filters){ |
|
|
|
QStringList Filters){ |
|
|
|
unsigned int NumFilters=Filters.size(); |
|
|
|
|
|
|
|
|
|
|
|
GtkWidget *FileDlg; |
|
|
|
GtkWidget *FileDlg; |
|
|
|
QString filename; |
|
|
|
QString filename; |
|
|
|
gtk_init(0,0); |
|
|
|
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_FILE_CHOOSER_ACTION_OPEN, |
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
|
|
|
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, |
|
|
|
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, |
|
|
|
NULL); |
|
|
|
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); |
|
|
|
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]); |
|
|
|
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(FileDlg),filters[i]); |
|
|
|
} |
|
|
|
} |
|
|
|
if (gtk_dialog_run(GTK_DIALOG(FileDlg)) == GTK_RESPONSE_ACCEPT){ |
|
|
|
if (gtk_dialog_run(GTK_DIALOG(FileDlg)) == GTK_RESPONSE_ACCEPT){ |
|
|
|
char* filename_cstring=gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(FileDlg)); |
|
|
|
char* filename_cstring=gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(FileDlg)); |
|
|
|
filename = QString::fromUtf8(filename_cstring); |
|
|
|
filename = QString::fromUtf8(filename_cstring); |
|
|
|
g_free(filename_cstring); |
|
|
|
g_free(filename_cstring); |
|
|
|
} |
|
|
|
}
|
|
|
|
gtk_widget_destroy (FileDlg); |
|
|
|
gtk_widget_destroy(FileDlg); |
|
|
|
return filename; |
|
|
|
return filename; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
GtkFileFilter** GnomePlugin::parseFilterStrings(const QStringList& filters){ |
|
|
|
GtkFileFilter** GnomePlugin::parseFilterStrings(const QStringList& filters){ |
|
|
|
if(!filters.size())return NULL; |
|
|
|
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++){ |
|
|
|
for(int i=0;i<filters.size();i++){ |
|
|
|
f[i]=gtk_file_filter_new(); |
|
|
|
f[i]=gtk_file_filter_new(); |
|
|
|
QString name; |
|
|
|
QString name; |
|
|
@ -63,12 +62,13 @@ GtkFileFilter** GnomePlugin::parseFilterStrings(const QStringList& filters){ |
|
|
|
else |
|
|
|
else |
|
|
|
break;
|
|
|
|
break;
|
|
|
|
} |
|
|
|
} |
|
|
|
gtk_file_filter_set_name(f[i],CSTRING(name)); |
|
|
|
gtk_file_filter_set_name(f[i],CSTR(name)); |
|
|
|
p++; |
|
|
|
p++; |
|
|
|
QString pattern; |
|
|
|
QString pattern; |
|
|
|
for(p;p<filters[i].size()-1;p++){ |
|
|
|
for(p;p<filters[i].size();p++){ |
|
|
|
if(filters[i][p]==' '){ |
|
|
|
if(filters[i][p]==' ' || filters[i][p]==')'){ |
|
|
|
gtk_file_filter_add_pattern(f[i],CSTRING(pattern)); |
|
|
|
gtk_file_filter_add_pattern(f[i],CSTR(pattern)); |
|
|
|
|
|
|
|
qDebug(CSTR(pattern)); |
|
|
|
pattern=QString(); |
|
|
|
pattern=QString(); |
|
|
|
} |
|
|
|
} |
|
|
|
else{ |
|
|
|
else{ |
|
|
@ -80,4 +80,34 @@ GtkFileFilter** GnomePlugin::parseFilterStrings(const QStringList& filters){ |
|
|
|
return f; |
|
|
|
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();} |