#include <shlobj.h>
#endif
-int getvnchomedir(char **dirp)
+static int gethomedir(char **dirp, bool userDir)
{
#ifndef WIN32
char *homedir, *dir;
return -1;
memcpy(dir, homedir, len);
- memcpy(dir + len, "/.vnc/\0", 7);
+ if (userDir)
+ dir[len]='\0';
+ else
+ memcpy(dir + len, "/.vnc/\0", 7);
#else
dir = new TCHAR[MAX_PATH];
if (dir == NULL)
return -1;
- ret = SHGetSpecialFolderPath(NULL, dir, CSIDL_APPDATA, FALSE);
+ if (userDir)
+ ret = SHGetSpecialFolderPath(NULL, dir, CSIDL_PROFILE, FALSE);
+ else
+ ret = SHGetSpecialFolderPath(NULL, dir, CSIDL_APPDATA, FALSE);
+
if (ret == FALSE) {
delete [] dir;
return -1;
}
- memcpy(dir+strlen(dir), (TCHAR *)"\\vnc\\\0", 6);
+ if (userDir)
+ dir[strlen(dir)+1] = '\0';
+ else
+ memcpy(dir+strlen(dir), (TCHAR *)"\\vnc\\\0", 6);
#endif
*dirp = dir;
return 0;
}
+
+int getvnchomedir(char **dirp)
+{
+ return gethomedir(dirp, false);
+}
+
+int getuserhomedir(char **dirp)
+{
+ return gethomedir(dirp, true);
+}
+
#include <errno.h>
#include <algorithm>
+#include <libgen.h>
#include <FL/Fl.H>
#include <FL/Fl_Input.H>
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;
ServerDialog::~ServerDialog()
{
+ if (usedDir)
+ free(usedDir);
}
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();
}
const char* filename = file_chooser->value();
+ dialog->updateUsedDir(filename);
try {
dialog->serverName->value(loadViewerParameters(filename));
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();
}
filename = file_chooser->value();
+ dialog->updateUsedDir(filename);
FILE* f = fopen(filename, "r");
if (f) {
// 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;
}
}
fclose(f);
}
+
+void ServerDialog::updateUsedDir(const char* filename)
+{
+ char * name = strdup(filename);
+ usedDir = strdup(dirname(name));
+ free(name);
+}