⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kpassport.cc

📁 linux上网直通车的整个程序(含源程序)初版(可供局域网
💻 CC
字号:
#include "Kpassport.h"#include "SettingDlg.h"#include "AboutDlg.h"#include <sigc++/slot.h>#include <sys/queue.h>#include "pixbuf/pixbuf.h"//#include <stdlib.h>//还有如果用户直接关闭程序,也应该先决断当前是否已经登陆,如果已经登陆就//先logout再....CKpassport::CKpassport():m_vbox_main(FALSE,0),                         m_frame_account("帐号信息"),                         m_table_account(3,4,FALSE),                         m_label_username("用户名:"),                         m_label_password("密  码:"),                         m_checkbutton_isinternational("登陆国际网站(国际帐号)"),                         m_image_logo(Gdk::Pixbuf::create_from_inline(24+16384,logo_pix,false)),			             m_image_connect(Gdk::Pixbuf::create_from_inline(24+1024,connect_pix,false)),                         m_label_connect("登陆"),                         m_image_exit(Gdk::Pixbuf::create_from_inline(24+1024,exit_pix,false)),                         m_label_exit("退出"),                         m_image_setting(Gdk::Pixbuf::create_from_inline(24+1024,setting_pix,false)),                         m_label_setting("设置"),                          m_image_about(Gdk::Pixbuf::create_from_inline(24+1024,about_pix,false)),                         m_label_about("关于"),                                                               			 m_label_connectinfo("[当前状态]:"),			                          m_label_connectstatus(" 离线中    "),                         m_hbox_buttons(FALSE,10){    IsCurLogin = false;    IsSettingChanged = false;    //------------------------------------------------    set_icon(Gdk::Pixbuf::create_from_inline(24+16384,logo_pix,false));    set_border_width(15);    set_position(Gtk::WIN_POS_CENTER);    set_resizable(FALSE);    set_title(" Kpassport 0.01 Version (Gtkmm)");    //Add Main VBox    add(m_vbox_main);      //Add Account Information Frame       m_vbox_main.add(m_frame_account);    m_table_account.set_border_width(10);    m_table_account.set_col_spacings(5); 	m_table_account.set_row_spacings(5);    m_frame_account.add(m_table_account);    m_entry_password.set_visibility(false);    m_label_connectstatus.set_justify(Gtk::JUSTIFY_LEFT);    m_label_connectstatus.modify_fg(Gtk::STATE_NORMAL , Gdk::Color("blue"));    //---------------    //m_entry_username.signal_changed().connect(sigc::mem_fun(*this,&CKpassport::on_entry_username_changed));    //m_entry_password.signal_changed().connect(sigc::mem_fun(*this,&CKpassport::on_entry_password_changed));    m_checkbutton_isinternational.signal_released().connect(sigc::mem_fun(*this,&CKpassport::on_checkbutton_isinter_released));    //-----------------         m_table_account.attach(m_label_username,0,1,0,1,Gtk::FILL,Gtk::FILL,0,0);    m_table_account.attach(m_entry_username,1,2,0,1,Gtk::FILL,Gtk::FILL,0,0);    m_table_account.attach(m_label_password,0,1,1,2,Gtk::FILL,Gtk::FILL,0,0);    m_table_account.attach(m_entry_password,1,2,1,2,Gtk::FILL,Gtk::FILL,0,0);    m_table_account.attach(m_checkbutton_isinternational,0,2,2,3,Gtk::EXPAND,Gtk::EXPAND,5,2);    m_table_account.attach(m_image_logo,2,3,0,2,Gtk::FILL,Gtk::FILL,15,0);    m_table_account.attach(m_label_connectinfo,0,1,3,4,Gtk::FILL,Gtk::FILL,0,0);    m_table_account.attach(m_label_connectstatus,1,2,3,4,Gtk::SHRINK,Gtk::SHRINK,0,0);       //Add Buttons    m_hbox_buttons.set_border_width(15);    m_vbox_main.add(m_hbox_buttons);    //login and logout button:    m_hbox_connect.add(m_image_connect);    m_hbox_connect.add(m_label_connect);    m_button_connect.add(m_hbox_connect);        m_button_connect.signal_clicked().connect(sigc::mem_fun(*this,&CKpassport::on_button_connect_clicked));    m_hbox_buttons.add(m_button_connect);    //exit button:       //m_button_exit.add_pixlabel("Resource/images/exit.png", "退出");     m_hbox_exit.add(m_image_exit);    m_hbox_exit.add(m_label_exit);    m_button_exit.add(m_hbox_exit);     m_button_exit.signal_clicked().connect(sigc::mem_fun(*this,&CKpassport::on_button_exit_clicked));    m_hbox_buttons.add(m_button_exit);    //setting button:    // m_button_setting.add_pixlabel("Resource/images/setting.png", "设置");     m_hbox_setting.add(m_image_setting);    m_hbox_setting.add(m_label_setting);    m_button_setting.add(m_hbox_setting);    m_button_setting.signal_clicked().connect(sigc::mem_fun(*this,&CKpassport::on_button_setting_clicked));    m_hbox_buttons.add(m_button_setting);    //about button:    // m_button_about.add_pixlabel("Resource/images/about.png", "关于");     m_hbox_about.add(m_image_about);    m_hbox_about.add(m_label_about);    m_button_about.add(m_hbox_about);       m_button_about.signal_clicked().connect(sigc::mem_fun(*this,&CKpassport::on_button_about_clicked));    m_hbox_buttons.add(m_button_about);    //----------------------====================================================================================    //Initialize the MyAccoutInfoManager struc        memset(MyAccountInfo.Username,0,sizeof(MyAccountInfo.Username));    memset(MyAccountInfo.Password,0,sizeof(MyAccountInfo.Password));    MyAccountInfo.IsInternational = 1;    MyAccountInfo.RefreshTimeInterval = 60;    MyAccountInfo.ConnectionTimeout = 5;    MyAccountInfo.IsSaveUsername = 1;    MyAccountInfo.IsSavePassword = 1;    MyAccountInfo.IsAutoLogin = 1;    MyAccountInfo.IsMinToTray = 1;       //Load Accout Settings and Set some controls's status    MyAccountInfoManager.GetAccountInfo(&MyAccountInfo);             #ifdef _DEBUG_    printf("%s\n%s\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n",MyAccountInfo.Username,MyAccountInfo.Password,MyAccountInfo.IsInternational,MyAccountInfo.RefreshTimeInterval,MyAccountInfo.ConnectionTimeout,MyAccountInfo.IsSaveUsername,MyAccountInfo.IsSavePassword,MyAccountInfo.IsAutoLogin,MyAccountInfo.IsMinToTray);      #endif            if( MyAccountInfo.IsSaveUsername == 0 )        m_entry_username.set_text(MyAccountInfo.Username);    if( MyAccountInfo.IsSavePassword ==0 )        m_entry_password.set_text(MyAccountInfo.Password);    if( MyAccountInfo.IsInternational == 0 )        m_checkbutton_isinternational.set_active(true);                 //---------------------------------------------------    show_all_children();    //Auto Login??    if(MyAccountInfo.IsAutoLogin == 0)        on_button_connect_clicked();    //===========================================================================================================         }CKpassport::~CKpassport(){    //printf("~CKpassport()\n");    //if changed , then save configuration to file....    if(IsCurLogin)    {	    passport.Logout();  #ifdef _DEBUG_	    printf("Logout before exit kpassport\n");#endif    }    //如果用户名或密码变了,也要保存新的信息    if(strcmp(MyAccountInfo.Username,m_entry_username.get_text().c_str()) != 0 || strcmp(MyAccountInfo.Password,m_entry_password.get_text().c_str()) !=0 )	    IsSettingChanged = true;		           //---------------------------------------    if (IsSettingChanged == true)    {#ifdef _DEBUG_	printf("save setting\n");#endif        //先取得当前用户名和密码: 注意 struct MyAccountInfo中的可能是过时的....        strcpy(MyAccountInfo.Username,m_entry_username.get_text().c_str());         strcpy(MyAccountInfo.Password,m_entry_password.get_text().c_str());                  //取得帐号类型          //MyAccountInfo.IsInternational = m_checkbutton_isinternational.get_active();#ifdef _DEBUG_	if(MyAccountInfo.IsInternational == 0  )               printf("set international ############\n");        else	       printf("set non-international*********\n");#endif	            //如果不保存用户名,清空用户名和密码并取消自动登陆        if(MyAccountInfo.IsSaveUsername == 1)        {            strcpy(MyAccountInfo.Username,"");            strcpy(MyAccountInfo.Password,"");        }        //如果不保存密码,则清空密码..        else if(MyAccountInfo.IsSavePassword == 1)        {             strcpy(MyAccountInfo.Password,"");        }       //Test....#ifdef _DEBUG_       printf("%s %s %d %d %d %d %d %d %d\n",MyAccountInfo.Username,MyAccountInfo.Password,MyAccountInfo.IsInternational,MyAccountInfo.RefreshTimeInterval,MyAccountInfo.ConnectionTimeout, MyAccountInfo.IsSaveUsername,MyAccountInfo.IsSavePassword,MyAccountInfo.IsAutoLogin,MyAccountInfo.IsMinToTray);#endif       MyAccountInfoManager.SaveAccountInfo(MyAccountInfo);     }   }//-------------------------------------------/*void CKpassport::Refresh(){    //gdk_threads_enter();    while(IsCurLogin)     {        sleep(MyAccountInfo.RefreshTimeInterval);        passport.Refresh();        m_label_connectstatus.set_text(passport.GetLastError());        #ifdef _DEBUG_                printf("成功刷新:%s\n",passport.GetLastError());        #endif    }#ifdef _DEBUG_    printf("IsCurLogin = false, Exit Refresh\n");#endif        //gdk_threads_leave();   }*************/void CKpassport::LoginAndRefresh(){        	//登陆前设置连接超时	passport.SetConnectionTimeout(MyAccountInfo.ConnectionTimeout);#ifdef _DEBUG_	printf("超时时间: %d\n", MyAccountInfo.ConnectionTimeout);#endif	        //设置是否国际帐号        //passport.SetInternational(m_checkbutton_isinternational.get_active());	passport.SetInternational(MyAccountInfo.IsInternational==1?false:true);#ifdef _DEBUG_	printf("国际帐号:%d\n",MyAccountInfo.IsInternational);#endif        //取得用户名和密码:因为Passport类会对用户名和密码进行编码,所以用复制的方法...        char username[100], password[100];        memset(username,0,100);        memset(password,0,100);        strcpy(username,m_entry_username.get_text().c_str());         strcpy(password,m_entry_password.get_text().c_str());               //尝试登陆并显示服务器返回的信息...                                    if(!passport.Login(username,password))        {            m_label_connectstatus.set_text(passport.GetLastError());            return;                     }                 //Login Success : -_________-然后设置控件的状态。。        IsCurLogin = true;        //m_button_connect.set_label("注销");             m_label_connect.set_label("注销");        //设置用户名和密码entry为不可编辑状态                    m_entry_username.set_editable(false);        m_entry_password.set_editable(false);        //设置是否国际帐号按钮为不可改变: ?????        //m_checkbutton_isinternational.set_focus_on_click(false);        //----------------------------------------------------------        //显示成功登陆的信息            m_label_connectstatus.set_text(passport.GetLastError());        //持续刷新        while(IsCurLogin)         {           sleep(MyAccountInfo.RefreshTimeInterval);           passport.Refresh();           m_label_connectstatus.set_text(passport.GetLastError());           #ifdef _DEBUG_                   printf("成功刷新:%s\n",passport.GetLastError());           #endif        }    }void CKpassport::Logout(){        IsCurLogin =false;        m_label_connect.set_label("登陆");        passport.Logout();        m_label_connectstatus.set_text(passport.GetLastError());                //重新设置用户名和密码entry为可编辑状态                    m_entry_username.set_editable(true);        m_entry_password.set_editable(true); }void CKpassport::on_button_connect_clicked(){    #ifdef _DEBUG_    printf("button connect\n");    #endif    if(!IsCurLogin)    {        //检查是否输入了用户名        if(m_entry_username.get_text_length() ==0 )        {            Gtk::MessageDialog dialog(*this, "友情提示: \n\n  请先输入帐号名!", false, Gtk::MESSAGE_WARNING);            dialog.run();            return;        }               //检查是否输入了密码        if(m_entry_password.get_text_length() ==0 )        {            Gtk::MessageDialog dialog(*this, "友情提示: \n\n  请先输入帐号密码!", false , Gtk::MESSAGE_WARNING);            dialog.run();            return;        }                Glib::Thread::create(sigc::mem_fun(*this,&CKpassport::LoginAndRefresh), false);	    }    else    {                 Glib::Thread::create(sigc::mem_fun(*this,&CKpassport::Logout), false);    }}void CKpassport::on_button_exit_clicked(){    //如果没有注销,则注销先.........    在析构函数中注销好了...#ifdef _DEBUG_    printf("button exit\n");#endif    hide();    }void CKpassport::on_button_setting_clicked(){#ifdef _DEBUG_    printf("button setting\n");#endif    CSettingDlg SettingDlg;     //-------------------------------------------------------    //Set some controls' status:    if( MyAccountInfo.IsSaveUsername == 0 )        SettingDlg.m_CheckButton_IsSaveName.set_active(true);    if( MyAccountInfo.IsSavePassword ==0 )        SettingDlg.m_CheckButton_IsSavePwd.set_active(true);           if(MyAccountInfo.IsAutoLogin == 0)        SettingDlg.m_CheckButton_IsAutoLogin.set_active(true);    if(MyAccountInfo.IsMinToTray == 0 )        SettingDlg.m_CheckButton_IsMinToTray.set_active(true);      SettingDlg.m_SpinButton_RefreshInterval.set_value(MyAccountInfo.RefreshTimeInterval);     SettingDlg.m_SpinButton_ConnectionTimeout.set_value(MyAccountInfo.ConnectionTimeout);    //-------------------------------------------------------       if( SettingDlg.run()==Gtk::RESPONSE_OK)    {        //save changes        SettingDlg.m_CheckButton_IsSaveName.get_active()==true? MyAccountInfo.IsSaveUsername=0:MyAccountInfo.IsSaveUsername = 1;        SettingDlg.m_CheckButton_IsSavePwd.get_active()==true? MyAccountInfo.IsSavePassword = 0: MyAccountInfo.IsSavePassword = 1;        SettingDlg.m_CheckButton_IsAutoLogin.get_active()==true?MyAccountInfo.IsAutoLogin = 0:MyAccountInfo.IsAutoLogin = 1;        SettingDlg.m_CheckButton_IsMinToTray.get_active()==true?MyAccountInfo.IsMinToTray = 0 :MyAccountInfo.IsMinToTray =1 ;               MyAccountInfo.RefreshTimeInterval = SettingDlg.m_SpinButton_RefreshInterval.get_value_as_int();	MyAccountInfo.ConnectionTimeout = SettingDlg.m_SpinButton_ConnectionTimeout.get_value_as_int();           //标志当前帐号的设置已经改变,退出时要保存新配置:        IsSettingChanged = true;            }}void CKpassport::on_button_about_clicked(){	#ifdef _DEBUG_    printf("button about\n");#endif    CAboutDlg AboutKpassport;    AboutKpassport.run();    }void CKpassport::on_checkbutton_isinter_released(){		MyAccountInfo.IsInternational = !MyAccountInfo.IsInternational;	IsSettingChanged = true;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -