• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

yapet/fileopen.h

Go to the documentation of this file.
00001 // -*- c++ -*-
00002 //
00003 // $Id: fileopen.h 3342 2010-09-17 18:32:00Z java $
00004 //
00005 // Copyright (C) 2008-2010  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 YAPET::UI::BaseWindow {
00056     private:
00057         enum {
00064             FALLBACK_PATH_MAX = 255
00065         };
00066 
00067         std::string title;
00068         WINDOW* window;
00069         YAPET::UI::ListWidget<YAPET::UI::secstring>* dir;
00070         YAPET::UI::ListWidget<YAPET::UI::secstring>* files;
00071         YAPET::UI::InputWidget* input;
00072         YAPET::UI::Button* okbutton;
00073         YAPET::UI::Button* cancelbutton;
00074 
00075         bool canceled;
00076 
00077         inline FileOpen (const FileOpen&) {}
00078         inline const FileOpen& operator= (const FileOpen&) {
00079             return *this;
00080         }
00081 
00082         YAPET::UI::secstring directory;
00083         YAPET::UI::secstring filename;
00084 
00085         inline int windowWidth() {
00086             return maxX() - 8;
00087         }
00088 
00089         inline int windowHeight() {
00090             return maxY() - 4;
00091         }
00092 
00093         inline int startX() {
00094             return minX() + 4;
00095         }
00096 
00097         inline int startY() {
00098             return minY() + 2;
00099         }
00100 
00101         void createWindows() throw (YAPET::UI::UIException);
00102 
00103         void printTitle() throw (YAPET::UI::UIException);
00104 
00105         void printCWD() throw (YAPET::UI::UIException);
00106 
00107     protected:
00108         void getEntries (std::list<YAPET::UI::secstring>& d,
00109                          std::list<YAPET::UI::secstring>& f)
00110         throw (YAPET::UI::UIException);
00111 
00112         void getcwd() throw (YAPET::UI::UIException);
00113         void cd (const YAPET::UI::secstring d) throw (YAPET::UI::UIException);
00114 
00115     public:
00116         FileOpen (std::string t) throw (YAPET::UI::UIException);
00117         virtual ~FileOpen();
00118 
00119         void run() throw (YAPET::UI::UIException);
00120         void refresh() throw (YAPET::UI::UIException);
00121 
00122         void resize() throw (YAPET::UI::UIException);
00123 
00124         std::string getFilepath();
00125 
00126         inline bool isCanceled() const {
00127             return filename.empty() ? true : canceled;
00128         }
00129 };
00130 
00131 inline
00132 bool endswith (YAPET::UI::secstring h, YAPET::UI::secstring n) {
00133     if (n.length() > h.length() )
00134         return false;
00135 
00136     if ( h.substr (h.length() - n.length(), n.length() ) == n)
00137         return true;
00138 
00139     return false;
00140 }
00141 
00142 inline
00143 bool endswith (std::string h, std::string n) {
00144     if (n.length() > h.length() )
00145         return false;
00146 
00147     if ( h.substr (h.length() - n.length(), n.length() ) == n)
00148         return true;
00149 
00150     return false;
00151 }
00152 
00153 #endif // _FILEOPEN_H

Generated on Sun Sep 19 2010 15:37:14 for YAPET by  doxygen 1.7.1