aboutsummaryrefslogtreecommitdiffstats
path: root/vncviewer
diff options
context:
space:
mode:
authorJohannes <bensky@arcor.de>2021-09-12 14:58:22 +0200
committerJohannes <bensky@arcor.de>2021-09-21 10:30:50 +0200
commit6c8dc447ce0fb26285c5b9236aded88f097b1b10 (patch)
tree7a44d0145f9651dd2f5e0371d136de6bcc8d2344 /vncviewer
parent62c8f8d92d6afd168cd8d4f45c4199342e23bc34 (diff)
downloadtigervnc-6c8dc447ce0fb26285c5b9236aded88f097b1b10.tar.gz
tigervnc-6c8dc447ce0fb26285c5b9236aded88f097b1b10.zip
Adjust default directory for configuration file save and load
Diffstat (limited to 'vncviewer')
-rw-r--r--vncviewer/ServerDialog.cxx37
-rw-r--r--vncviewer/ServerDialog.h2
2 files changed, 30 insertions, 9 deletions
diff --git a/vncviewer/ServerDialog.cxx b/vncviewer/ServerDialog.cxx
index ba0386ca..56933591 100644
--- a/vncviewer/ServerDialog.cxx
+++ b/vncviewer/ServerDialog.cxx
@@ -23,6 +23,7 @@
#include <errno.h>
#include <algorithm>
+#include <libgen.h>
#include <FL/Fl.H>
#include <FL/Fl_Input.H>
@@ -67,6 +68,7 @@ ServerDialog::ServerDialog()
y = margin;
serverName = new Fl_Input_Choice(x, y, w() - margin*2 - server_label_width, INPUT_HEIGHT, _("VNC server:"));
+ usedDir = NULL;
int adjust = (w() - 20) / 4;
int button_width = adjust - margin/2;
@@ -119,6 +121,8 @@ ServerDialog::ServerDialog()
ServerDialog::~ServerDialog()
{
+ if (usedDir)
+ free(usedDir);
}
@@ -164,8 +168,12 @@ void ServerDialog::handleOptions(Fl_Widget *widget, void *data)
void ServerDialog::handleLoad(Fl_Widget *widget, void *data)
{
ServerDialog *dialog = (ServerDialog*)data;
- Fl_File_Chooser* file_chooser = new Fl_File_Chooser("", _("TigerVNC configuration (*.tigervnc)"),
- 0, _("Select a TigerVNC configuration file"));
+
+ if (!dialog->usedDir)
+ getuserhomedir(&(dialog->usedDir));
+
+ Fl_File_Chooser* file_chooser = new Fl_File_Chooser(dialog->usedDir, _("TigerVNC configuration (*.tigervnc)"),
+ 0, _("Select a TigerVNC configuration file"));
file_chooser->preview(0);
file_chooser->previewButton->hide();
file_chooser->show();
@@ -181,6 +189,7 @@ void ServerDialog::handleLoad(Fl_Widget *widget, void *data)
}
const char* filename = file_chooser->value();
+ dialog->updateUsedDir(filename);
try {
dialog->serverName->value(loadViewerParameters(filename));
@@ -199,9 +208,11 @@ void ServerDialog::handleSaveAs(Fl_Widget *widget, void *data)
ServerDialog *dialog = (ServerDialog*)data;
const char* servername = dialog->serverName->value();
const char* filename;
-
- Fl_File_Chooser* file_chooser = new Fl_File_Chooser("", _("TigerVNC configuration (*.tigervnc)"),
- 2, _("Save the TigerVNC configuration to file"));
+ if (!dialog->usedDir)
+ getuserhomedir(&dialog->usedDir);
+
+ Fl_File_Chooser* file_chooser = new Fl_File_Chooser(dialog->usedDir, _("TigerVNC configuration (*.tigervnc)"),
+ 2, _("Save the TigerVNC configuration to file"));
file_chooser->preview(0);
file_chooser->previewButton->hide();
@@ -220,6 +231,7 @@ void ServerDialog::handleSaveAs(Fl_Widget *widget, void *data)
}
filename = file_chooser->value();
+ dialog->updateUsedDir(filename);
FILE* f = fopen(filename, "r");
if (f) {
@@ -227,12 +239,12 @@ void ServerDialog::handleSaveAs(Fl_Widget *widget, void *data)
// The file already exists.
fclose(f);
int overwrite_choice = fl_choice(_("%s already exists. Do you want to overwrite?"),
- _("Overwrite"), _("No"), NULL, filename);
+ _("Overwrite"), _("No"), NULL, filename);
if (overwrite_choice == 1) {
- // If the user doesn't want to overwrite:
- file_chooser->show();
- continue;
+ // If the user doesn't want to overwrite:
+ file_chooser->show();
+ continue;
}
}
@@ -388,3 +400,10 @@ void ServerDialog::saveServerHistory()
fclose(f);
}
+
+void ServerDialog::updateUsedDir(const char* filename)
+{
+ char * name = strdup(filename);
+ usedDir = strdup(dirname(name));
+ free(name);
+}
diff --git a/vncviewer/ServerDialog.h b/vncviewer/ServerDialog.h
index 83639777..f9c3d136 100644
--- a/vncviewer/ServerDialog.h
+++ b/vncviewer/ServerDialog.h
@@ -45,10 +45,12 @@ protected:
private:
void loadServerHistory();
void saveServerHistory();
+ void updateUsedDir(const char* filename);
protected:
Fl_Input_Choice *serverName;
std::vector<std::string> serverHistory;
+ char *usedDir;
};
#endif