• Main Page
  • Namespaces
  • Data Structures
  • Files
  • File List

/www/proggenOrg/dedupe/export/trunk/userinterface/gui/ncurses/implementation.cpp

00001 // NCures "Hello World!" program, taken from
00002 // http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/helloworld.html
00003 #include <curses.h>
00004 #include <panel.h>
00005 #include "implementation.h"
00006 #include <cstdlib>
00007 #include <string.h>
00008 
00009 namespace Dedupe
00010 {
00011   namespace GUI
00012   {
00013     NCursesControl::NCursesControl( NCursesDialog & dialog, unsigned int x, unsigned int y, unsigned int width, unsigned int height )
00014       : Markable( dialog.Controls )
00015     {
00016       Window = subwin( dialog.GetWindow(), height, width, y, x );
00017       wborder( Window, ACS_VLINE, ACS_VLINE, ACS_HLINE, ACS_HLINE, ACS_ULCORNER, ACS_URCORNER, ACS_LLCORNER, ACS_LRCORNER );
00018     }
00019 
00020     NCursesListView::NCursesListView( NCursesDialog & dialog, unsigned int x, unsigned int y, unsigned int width, unsigned int height )
00021       : NCursesControl( dialog, x, y, width, height )
00022     {
00023     }
00024 
00025     void NCursesListView::RefreshMark()
00026     {
00027       flash();
00028     }
00029 
00030     NCursesButton::NCursesButton( NCursesDialog & dialog, unsigned int x, unsigned int y, unsigned int width, char const * text )
00031       : NCursesControl( dialog, x, y, 2+width, 3 )
00032     {
00033       SetText( text );
00034     }
00035 
00036     void NCursesButton::SetText( char const * text )
00037     {
00038       Text = text;
00039       RefreshText();
00040     }
00041 
00042     void NCursesButton::RefreshMark()
00043     {
00044       RefreshText();
00045     }
00046 
00047     void NCursesButton::RefreshText()
00048     {
00049       int width, strl;
00050 
00051       width = getmaxx( Window ) - 2;
00052       strl = strlen( Text );
00053       if( strl > width )
00054         strl = width;
00055 
00056       int left = ( width - strl ) / 2;
00057       int right = width - strl - left;
00058 
00059       wcolor_set( Window, NCursesMain::DefaultColorPair, 0 );
00060       mvwaddch( Window, 1, 0, ACS_VLINE );
00061 
00062       if( Marked() )
00063         wcolor_set( Window, NCursesMain::MarkedColorPair, 0 );
00064       else
00065         wcolor_set( Window, NCursesMain::DefaultColorPair, 0 );
00066 
00067       while( left-- )
00068         waddch( Window, ' ' );
00069 
00070       waddnstr( Window, Text, strl );
00071 
00072       while( right-- )
00073         waddch( Window, ' ' );
00074 
00075       wrefresh( Window );
00076     }
00077 
00078     NCursesButton::~NCursesButton()
00079     {
00080       delwin( Window );
00081     }
00082 
00083     NCursesMain::NCursesMain( int argc, char *argv[] )
00084       : Main( argc, argv )
00085     {
00086       char * temp = getenv( "ESCDELAY" );
00087       setenv( "ESCDELAY", "25", 1 );
00088 
00089       Window = initscr();
00090       noecho();
00091       start_color();
00092 
00093       mvaddstr( 15, 10, temp );
00094 
00095       int width, height;
00096       getmaxyx( Window, height, width );
00097 
00098       int posy = height - 4;
00099       int itemWidth = width - 2 - 12;
00100       itemWidth /= 3;
00101 
00102       init_pair( DefaultColorPair, COLOR_GREEN, COLOR_BLUE );
00103       init_pair( MarkedColorPair, COLOR_BLUE, COLOR_YELLOW );
00104       bkgd( COLOR_PAIR(1));
00105 
00106       Index    = new NCursesButton( *this, 1 + 2                      , posy, itemWidth, "Indizieren" );
00107       Index->SetMark( true );
00108       Trashcan = new NCursesButton( *this, 1 + 2 + ( 3+itemWidth )    , posy, itemWidth, "Trashcan"   );
00109       Results  = new NCursesButton( *this, 1 + 2 + ( 3+itemWidth ) * 2, posy, itemWidth, "Results"    );
00110 
00111       itemWidth = ( width - 5 ) / 2;
00112       fileBrowser = new NCursesListView( *this, 3, 1, itemWidth, height - 5 );
00113       selectedFiles = new NCursesListView( *this, itemWidth+3, 1, itemWidth, height - 5 );
00114 
00115       border( ACS_VLINE, ACS_VLINE, ACS_HLINE, ACS_HLINE, ACS_ULCORNER, ACS_URCORNER, ACS_LLCORNER, ACS_LRCORNER );
00116       keypad( Window, true );
00117       curs_set(0);
00118 
00119       refresh();                        /* Print it on to the real screen */
00120     }
00121 
00122     NCursesMain::~NCursesMain()
00123     {
00124       curs_set(1);
00125       delete Index;
00126       delete Trashcan;
00127       delete Results;
00128 
00129       delete fileBrowser;
00130       delete selectedFiles;
00131 
00132       echo();
00133       endwin();
00134     }
00135 
00136     void NCursesMain::TrackFile( const Dedupe::FileInfo & file )
00137     {
00138       /* Liste erweitern */
00139     }
00140 
00141     void NCursesMain::UntrackFile( const Dedupe::FileInfo & file )
00142     {
00143       /* Liste modifizieren */
00144     }
00145 
00146     void NCursesMain::ClearTrackedFiles()
00147     {
00148 
00149     }
00150 
00151     bool NCursesMain::IsRecursive()
00152     {
00153 
00154     }
00155 
00156     int NCursesMain::exec()
00157     {
00158       int ch;
00159       while(( ch = getch() ))
00160       {
00161         switch( ch )
00162         {
00163           case 'q':
00164           case 27: return 0;
00165           case  9: case 'n':
00166           {
00167             MarkNextControl();
00168             break;
00169           }
00170           case 353: // Shift + Tab
00171           {
00172             MarkPrevControl();
00173             break;
00174           }
00175           case 'i': mvaddstr( 5, 5, "Index               " ); break;
00176           case 't': mvaddstr( 5, 5, "Trashcan            " ); break;
00177           case 'r': mvaddstr( 5, 5, "Results             " ); break;
00178           case '+': mvaddstr( 5, 5, "Add Item            " ); break;
00179           case '-': mvaddstr( 5, 5, "Remove Item         " ); break;
00180           default:
00181           {
00182             char temp[255];
00183             sprintf( temp, "Unknown Operation %d  ", ch );
00184             mvaddstr( 5, 5, temp );
00185             break;
00186           }
00187         }
00188       }
00189       return 0;
00190     }
00191 
00192   }
00193 }

Generated on Mon Mar 11 2013 12:04:52 for Dedupe by  doxygen 1.7.1