gtk_superuser.cc
上传用户:psq1974
上传日期:2007-01-06
资源大小:1195k
文件大小:4k
- /* Copyright (C) 1998, 1999 State University of New York at Stony Brook
- Author: Andrew V. Shuvalov ( andrew@ecsl.cs.sunysb.edu )
- Software license is located in file "COPYING"
- */
- #include <unistd.h>
- #include <gtk--.h>
- #include "session.h"
- #include "gtk_superuser.h"
- const int SuperuserPreferenciesWindow::topWindowInitSizeX = 700;
- const int SuperuserPreferenciesWindow::topWindowInitSizeY = 400;
- /**
- */
- SuLoginWindow::SuLoginWindow( Session &s )
- : session( s )
- {
- // make vertical box
- Gtk_VBox *top_vbox_layout = new Gtk_VBox();
- top_vbox_layout->set_spacing( 10 );
- {
- entry = new Gtk_Entry();
- top_vbox_layout->pack_start( *entry, FALSE, FALSE, 0 );
- entry->show();
- entry->set_visibility( false );
- entry->set_editable( true );
- Gtk_Button *but = new Gtk_Button( "Login" );
- top_vbox_layout->pack_start( *but, FALSE, FALSE, 0 );
- but->show();
- connect_to_method( but->clicked, this,
- &SuLoginWindow::callback_login );
- }
- add( top_vbox_layout );
- top_vbox_layout->show();
- set_title( "Video client: Login as superuser" );
- }
- void SuLoginWindow::callback_login()
- {
- string text = entry->get_text();
- text.c_str();
- session.login_superuser( text );
- hide();
- }
- // ------------------------------------------------------------------
- SuperuserPreferenciesWindow::SuperuserPreferenciesWindow( Session &s ) :
- session( s )
- {
- set_usize( topWindowInitSizeX, topWindowInitSizeY );
- // make vertical box
- Gtk_VBox *top_vbox_layout = new Gtk_VBox();
- {
- // scrolled w.
- Gtk_ScrolledWindow *scrWindow = new Gtk_ScrolledWindow();
- scrWindow->set_usize( topWindowInitSizeX, topWindowInitSizeY*9/10 );
- scrWindow->set_policy( GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS );
- scrWindow->show();
- // list
- profList = new Gtk_VBox();
- profList->show();
- scrWindow->add( profList );
-
- // button box
- Gtk_HButtonBox *hbb = new Gtk_HButtonBox();
- hbb->show();
- Gtk_Button *svb = new Gtk_Button( "Save" );
- svb->show();
- hbb->pack_start( *svb );
- connect_to_method( svb->clicked, this,
- &SuperuserPreferenciesWindow::callback_save );
- Gtk_Button *cab = new Gtk_Button( "Cancel" );
- cab->show();
- hbb->pack_start( *cab );
- connect_to_method( cab->clicked, this,
- &SuperuserPreferenciesWindow::callback_cancel );
- // paned
- Gtk_VPaned *vp = new Gtk_VPaned();
- vp->add1( *scrWindow );
- vp->add2( *hbb );
- vp->show();
- top_vbox_layout->pack_start( *vp, TRUE, TRUE, 0 );
- }
- add( top_vbox_layout );
- top_vbox_layout->show();
- // now add what can be edited
- props.clear();
- session.loadServerProperties( props );
- for( int i = 0; i < props.size(); i++ )
- {
- ServerConfigItem &ci = props[i];
- // hbox
- Gtk_HBox *hbox = new Gtk_HBox();
- hbox->show();
- profList->pack_start( *hbox );
- Gtk_Label *label = new Gtk_Label( ci.help.c_str() );
- label->set_usize( topWindowInitSizeX/2, 20 );
- label->show();
- hbox->pack_start( *label );
- Gtk_Entry *entry = new Gtk_Entry();
- entry->set_text( ci.value.c_str() );
- entry->show();
- entry->set_editable( true );
- hbox->pack_start( *entry );
- // and add to the list of entries
- entries.push_back( entry );
- }
- }
- void SuperuserPreferenciesWindow::update_from_screen()
- {
- for( int i = 0; i < entries.size(); i++ )
- {
- Gtk_Entry *entry = entries[i];
- if( !entry )
- continue;
- ServerConfigItem &ci = props[i];
- ci.value = entry->get_text();
- }
- }
- void SuperuserPreferenciesWindow::callback_save()
- {
- update_from_screen();
- session.saveServerProperties( props );
- hide();
- }
- void SuperuserPreferenciesWindow::callback_cancel()
- {
- hide();
- }