diff options
Diffstat (limited to 'plugingui')
-rw-r--r-- | plugingui/Makefile.am | 1 | ||||
-rw-r--r-- | plugingui/pluginconfig.cc | 130 | ||||
-rw-r--r-- | plugingui/pluginconfig.h | 48 | ||||
-rw-r--r-- | plugingui/plugingui.cc | 28 | ||||
-rw-r--r-- | plugingui/plugingui.h | 3 |
5 files changed, 210 insertions, 0 deletions
diff --git a/plugingui/Makefile.am b/plugingui/Makefile.am index 3cf60a5..79e25e4 100644 --- a/plugingui/Makefile.am +++ b/plugingui/Makefile.am @@ -26,6 +26,7 @@ EXTRA_DIST = \ button.h \ checkbox.h \ colour.h \ + config.h \ combobox.h \ directory.h \ eventhandler.h \ diff --git a/plugingui/pluginconfig.cc b/plugingui/pluginconfig.cc new file mode 100644 index 0000000..57a4e08 --- /dev/null +++ b/plugingui/pluginconfig.cc @@ -0,0 +1,130 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * config.cc + * + * Tue Jun 3 13:54:05 CEST 2014 + * Copyright 2014 Jonas Suhr Christensen + * jsc@umbraculum.org + ****************************************************************************/ + +/* + * This file is part of DrumGizmo. + * + * DrumGizmo is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * DrumGizmo is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with DrumGizmo; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include "config.h" + +#include <stdio.h> +#include <errno.h> +#include <string.h> +#include <stdlib.h> + +#include "directory.h" + +#ifdef WIN32 +#include <direct.h> +#include <windows.h> +#else +#endif + +#include <hugin.hpp> + +#define CONFIGFILENAME "plugingui.conf" + +#ifdef WIN32 + #define SEP "\\" + #define CONFIGDIRNAME "drumgizmo" +#else + #define SEP "/" + #define CONFIGDIRNAME ".drumgizmo" +#endif + +Config::Config() +{ + +} + +Config::~Config() +{ + +} + +FILE* openFilePtr(std::string mode) { +#ifdef WIN32 + TCHAR szPath[256]; + if(SUCCEEDED(SHGetFolderPath(NULL, + CSIDL_APPDATA | CSIDL_FLAG_CREATE, + NULL, + 0, + szPath))); { + DEBUG(config, "WINDOWS APP DATA PATH:%s\n", szPath); +// PathAppend(szPath, TEXT( +// PathAppend(szPath, TEXT(CONFIGFILENAME)); +// HANDLE hFile = CreateFile(szPath, GENERIC_READ | GENERIC_WRITE, 0, NULL); + } +#else + std::string configpath = strdup(getenv("HOME")); + configpath += SEP; + configpath += CONFIGDIRNAME; + if(!Directory::exists(configpath)) { + if( (mkdir(configpath.c_str(), 0755)) < 0) return NULL; + } +#endif + + FILE *fp; + std::string configfile = configpath; + configfile += SEP; + configfile += CONFIGFILENAME; + if(! (fp = fopen(configfile.c_str(), mode.c_str())) ) { + return NULL; + } + + return fp; +} + +void Config::load() +{ + FILE *fp = openFilePtr("r"); + if(!fp) return; + + lastkit.clear(); + lastmidimap.clear(); + + char buf[4096]; + while( fgets(buf, 4096, fp) ) { + if(!strncmp(buf, "lastkit:", 8)) { + // Dont copy newline + if(strlen(buf) > 8 + 1) lastkit.append(buf+8, strlen(buf+8) - 1); + } + if(!strncmp(buf, "lastmidimap:", 12)) { + // Dont copy newline + if(strlen(buf) > 12+1) lastmidimap.append(buf+12, strlen(buf+12) - 1); + } + } +} + +void Config::save() +{ + FILE *fp = openFilePtr("w"); + if(!fp) return; + + std::string buf; + buf.append("lastkit:" + lastkit + '\n'); + buf.append("lastmidimap:" + lastmidimap + '\n'); + + fputs(buf.c_str(), fp); + + fclose(fp); +} diff --git a/plugingui/pluginconfig.h b/plugingui/pluginconfig.h new file mode 100644 index 0000000..d0e9bcd --- /dev/null +++ b/plugingui/pluginconfig.h @@ -0,0 +1,48 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * config.h + * + * Tue Jun 3 13:51:29 CEST 2014 + * Copyright 2014 Jonas Suhr Christensen + * jsc@umbraculum.org + ****************************************************************************/ + +/* + * This file is part of DrumGizmo. + * + * DrumGizmo is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * DrumGizmo is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with DrumGizmo; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#ifndef __DRUMGIZMO_CONFIG_H__ +#define __DRUMGIZMO_CONFIG_H__ + +#include <string> +#include <list> + +#define DIRECTORY_HIDDEN 1 + +class Config { + + public: + Config(); + ~Config(); + + void load(); + void save(); + + std::string lastkit; + std::string lastmidimap; +}; + +#endif/*__DRUMGIZMO_CONFIG_H__*/ diff --git a/plugingui/plugingui.cc b/plugingui/plugingui.cc index 6601be7..86f3758 100644 --- a/plugingui/plugingui.cc +++ b/plugingui/plugingui.cc @@ -33,6 +33,7 @@ #include "verticalline.h" #include "../version.h" +#include "config.h" #include "messagehandler.h" static void checkClick(void *ptr) @@ -81,6 +82,12 @@ static void knobChange2(void *ptr) #endif } +static void quit(void *ptr) { + PluginGUI *gui = (PluginGUI*)ptr; + + gui->stopThread(); +} + GUI::FileBrowser *fb; static void selectKitFile(void *ptr, std::string filename) { @@ -91,6 +98,8 @@ static void selectKitFile(void *ptr, std::string filename) std::string drumkit = gui->lineedit->text(); + gui->config->lastkit = drumkit; + gui->progress->setProgress(0); gui->progress->setState(GUI::ProgressBar::blue); @@ -105,6 +114,7 @@ static void kitBrowseClick(void *ptr) PluginGUI *gui = (PluginGUI*)ptr; std::string path = gui->lineedit->text(); + if(path == "") path = gui->config->lastkit; if(path == "") path = gui->lineedit2->text(); fb->setPath(path); @@ -121,6 +131,8 @@ static void selectMapFile(void *ptr, std::string filename) std::string midimap = gui->lineedit2->text(); + gui->config->lastmidimap = midimap; + LoadMidimapMessage *msg = new LoadMidimapMessage(); msg->midimapfile = midimap; msghandler.sendMessage(MSGRCV_ENGINE, msg); @@ -137,6 +149,7 @@ static void midimapBrowseClick(void *ptr) PluginGUI *gui = (PluginGUI*)ptr; std::string path = gui->lineedit2->text(); + if(path == "") path = gui->config->lastmidimap; if(path == "") path = gui->lineedit->text(); fb->setPath(path); @@ -269,6 +282,10 @@ void PluginGUI::thread_main() void PluginGUI::deinit() { if(window) delete window; + if(config) { + config->save(); + delete config; + } } void closeEventHandler(void *ptr) @@ -280,6 +297,10 @@ void closeEventHandler(void *ptr) void PluginGUI::init() { DEBUG(gui, "init"); + + config = new Config(); + config->load(); + window = new GUI::Window(); window->eventHandler()->registerCloseHandler(closeEventHandler, (void*)&closing); @@ -428,6 +449,13 @@ void PluginGUI::init() filebrowser->hide(); fb = filebrowser; + // Enable quit button + GUI::Button *btn_quit = new GUI::Button(window); + btn_quit->setText("Quit"); + btn_quit->move(50,280); + btn_quit->resize(80,80); + btn_quit->registerClickHandler(quit, this); + window->show(); sem.post(); diff --git a/plugingui/plugingui.h b/plugingui/plugingui.h index 7ec5e77..9fb8d6a 100644 --- a/plugingui/plugingui.h +++ b/plugingui/plugingui.h @@ -36,6 +36,7 @@ #include "button.h" #include "knob.h" #include "progressbar.h" +#include "config.h" #include "filebrowser.h" @@ -80,6 +81,8 @@ public: GUI::LineEdit *lineedit2; GUI::ProgressBar *progress2; + Config *config; + void (*windowClosedHandler)(void *); void *windowClosedPtr; |