00001 // -*- c++ -*- 00002 // 00003 // $Id: fileopen.h 2360 2009-06-11 15:06:24Z rafi $ 00004 // 00005 // Copyright (C) 2008, 2009 Rafael Ostertag 00006 // 00007 // This file is part of YAPET. 00008 // 00009 // YAPET is free software: you can redistribute it and/or modify it under the 00010 // terms of the GNU General Public License as published by the Free Software 00011 // Foundation, either version 3 of the License, or (at your option) any later 00012 // version. 00013 // 00014 // YAPET is distributed in the hope that it will be useful, but WITHOUT ANY 00015 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00016 // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 00017 // details. 00018 // 00019 // You should have received a copy of the GNU General Public License along with 00020 // YAPET. If not, see <http://www.gnu.org/licenses/>. 00021 // 00022 00023 #ifndef _FILEOPEN_H 00024 #define _FILEOPEN_H 00025 00026 #ifdef HAVE_CONFIG_H 00027 # include <config.h> 00028 #endif 00029 00030 #ifdef HAVE_NCURSES_H 00031 # include <ncurses.h> 00032 #else // HAVE_NCURSES_H 00033 # ifdef HAVE_CURSES_H 00034 # include <curses.h> 00035 # else 00036 # error "Neither curses.h nor ncurses.h available" 00037 # endif // HAVE_CURSES_H 00038 #endif // HAVE_NCURSES_H 00039 #include "curswa.h" // Leave this here. It depends on the above includes. 00040 00041 #include <secstring.h> 00042 #include <basewindow.h> 00043 #include <listwidget.h> 00044 #include <button.h> 00045 #include <inputwidget.h> 00046 00055 class FileOpen : protected YAPETUI::BaseWindow { 00056 private: 00057 enum { 00064 FALLBACK_PATH_MAX=255 00065 }; 00066 00067 std::string title; 00068 WINDOW* window; 00069 YAPETUI::ListWidget<YAPETUI::secstring>* dir; 00070 YAPETUI::ListWidget<YAPETUI::secstring>* files; 00071 YAPETUI::InputWidget* input; 00072 YAPETUI::Button* okbutton; 00073 YAPETUI::Button* cancelbutton; 00074 00075 bool canceled; 00076 00077 00078 inline FileOpen(const FileOpen&) {} 00079 inline const FileOpen& operator=(const FileOpen&) { return *this; } 00080 00081 YAPETUI::secstring directory; 00082 YAPETUI::secstring filename; 00083 00084 inline int windowWidth() { 00085 return maxX() - 8; 00086 } 00087 00088 inline int windowHeight() { 00089 return maxY() - 4; 00090 } 00091 00092 inline int startX() { 00093 return minX() + 4; 00094 } 00095 00096 inline int startY() { 00097 return minY() + 2; 00098 } 00099 00100 void createWindows() throw(YAPETUI::UIException); 00101 00102 void printTitle() throw(YAPETUI::UIException); 00103 00104 void printCWD() throw(YAPETUI::UIException); 00105 00106 protected: 00107 void getEntries(std::list<YAPETUI::secstring>& d, 00108 std::list<YAPETUI::secstring>& f) 00109 throw(YAPETUI::UIException); 00110 00111 void getcwd() throw(YAPETUI::UIException); 00112 void cd(const YAPETUI::secstring d) throw(YAPETUI::UIException); 00113 00114 public: 00115 FileOpen(std::string t) throw(YAPETUI::UIException); 00116 virtual ~FileOpen(); 00117 00118 void run() throw(YAPETUI::UIException); 00119 void refresh() throw(YAPETUI::UIException); 00120 00121 void resize() throw(YAPETUI::UIException); 00122 00123 std::string getFilepath(); 00124 00125 inline bool isCanceled() const { return canceled; } 00126 }; 00127 00128 inline 00129 bool endswith(YAPETUI::secstring h, YAPETUI::secstring n) { 00130 if (n.length() > h.length()) 00131 return false; 00132 00133 if ( h.substr(h.length()-n.length(),n.length()) == n) 00134 return true; 00135 00136 return false; 00137 } 00138 00139 inline 00140 bool endswith(std::string h, std::string n) { 00141 if (n.length() > h.length()) 00142 return false; 00143 00144 if ( h.substr(h.length()-n.length(),n.length()) == n) 00145 return true; 00146 00147 return false; 00148 } 00149 00150 #endif // _FILEOPEN_H