yapet/fileopen.h

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

Generated on Wed Feb 27 16:15:42 2008 for YAPET by  doxygen 1.5.4