📄 win.cpp
字号:
/////////////////////////////////////////////////////////////////////////////
// Name: Win.cpp
// Copyright: wellgain
// Author: bet
// Date: 2003-10-17
// Description: implementation of the CWin class.
/////////////////////////////////////////////////////////////////////////////
#include "Win.h"
#include "messagebox.h"
#include "stdlib.h"
#include "msgqueue.h"
extern void wg_main_quit();
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CWin::CWin(char* title, CWidget* parent) : CWidget(parent)
{
if(title)
m_szTitle = g_strdup(title);
else
m_szTitle = NULL;
m_hHandle = Create();
gtk_signal_connect (GTK_OBJECT (m_hHandle), "destroy",
GTK_SIGNAL_FUNC (on_widget_destroy),
this);
Show();
m_pNotebook->ReLoadData();
m_pToolbar->SetActiveButton(0);
m_pNotebook->SetCallType(0);
}
CWin::~CWin()
{
if(m_szTitle)
g_free(m_szTitle);
if(m_pToolbar)
delete m_pToolbar;
if(m_pNotebook)
delete m_pNotebook;
for(int i=0; i<5; i++)
delete m_Buttons[i];
}
GtkWidget* CWin::Create()
{
// Window
GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_set_usize (window, 320, 215);
gtk_window_set_title (GTK_WINDOW (window), (m_szTitle));
gtk_window_set_policy (GTK_WINDOW (window), FALSE, FALSE, FALSE);
GtkWidget* fixed;
fixed = gtk_fixed_new ();
gtk_widget_show (fixed);
gtk_container_add (GTK_CONTAINER (window), fixed);
//notebook
m_pNotebook = new CNoteBook(this);
m_pNotebook->SetSize(320, 215-39);
gtk_fixed_put (GTK_FIXED(fixed), m_pNotebook->GetHandle(), 0, 17);
// toolbar
static gchar* xpm_file[] = { XPMFILEPATH "offen.xpm",
XPMFILEPATH "missed.xpm",
XPMFILEPATH "dialed.xpm",
XPMFILEPATH "received.xpm",
XPMFILEPATH "blacklist.xpm",
NULL
};
static gchar* xpm_down_file[] = { XPMFILEPATH "offen-down.xpm",
XPMFILEPATH "missed-down.xpm",
XPMFILEPATH "dialed-down.xpm",
XPMFILEPATH "received-down.xpm",
XPMFILEPATH "blacklist-down.xpm",
NULL
};
m_pToolbar = new CToolBar(this);
m_pToolbar->set_on_close_func(GtkSignalFunc(on_toolbar_close_button_click), this);
gtk_fixed_put(GTK_FIXED(fixed), m_pToolbar->GetHandle(), 0, 0);
int i=0;
CButton* but;
while(xpm_file[i]){
but = m_pToolbar->AddButton(xpm_file[i], xpm_down_file[i],
GtkSignalFunc(on_toolbar_button_pressed), this);
but->tag = i;
i++;
}
// buttons
GtkWidget *hbox;
hbox = gtk_hbox_new (FALSE, 0);
gtk_widget_set_usize(hbox, 320, 20);
gtk_fixed_put (GTK_FIXED(fixed), hbox, 0, 215-21);
gtk_widget_show (hbox);
m_Buttons[0] = new CButton(_("拨打"), this);
// m_Buttons[0]->Set_Relief(CButton::none);
gtk_widget_set_usize (m_Buttons[0]->GetHandle(), 40, 20);
gtk_signal_connect (GTK_OBJECT (m_Buttons[0]->GetHandle()), "clicked",
GTK_SIGNAL_FUNC (on_button_dial_clicked),
this);
gtk_box_pack_start (GTK_BOX (hbox), m_Buttons[0]->GetHandle(), TRUE, FALSE, 0);
m_Buttons[1] = new CButton(_("保存"), this);
// m_Buttons[1]->Set_Relief(CButton::none);
m_Buttons[1]->SetSize(40, 20);
gtk_signal_connect (GTK_OBJECT (m_Buttons[1]->GetHandle()), "clicked",
GTK_SIGNAL_FUNC (on_button_save_clicked),
this);
gtk_box_pack_start (GTK_BOX (hbox), m_Buttons[1]->GetHandle(), TRUE, FALSE, 0);
m_Buttons[2] = new CButton(_("删除"), this);
// m_Buttons[2]->Set_Relief(CButton::none);
m_Buttons[2]->SetSize(40, 20);
gtk_signal_connect (GTK_OBJECT (m_Buttons[2]->GetHandle()), "clicked",
GTK_SIGNAL_FUNC (on_button_del_clicked),
this);
gtk_box_pack_start (GTK_BOX (hbox), m_Buttons[2]->GetHandle(), TRUE, FALSE, 0);
m_Buttons[3] = new CButton(_("列入黑名单"), this);
// m_Buttons[3]->Set_Relief(CButton::none);
m_Buttons[3]->SetSize(70, 20);
gtk_signal_connect (GTK_OBJECT (m_Buttons[3]->GetHandle()), "clicked",
GTK_SIGNAL_FUNC (on_button_setblack_clicked),
this);
gtk_box_pack_start (GTK_BOX (hbox), m_Buttons[3]->GetHandle(), TRUE, FALSE, 0);
m_Buttons[4] = new CButton(_("通话时长"), this);
// m_Buttons[4]->Set_Relief(CButton::none);
m_Buttons[4]->SetSize(60, 20);
gtk_signal_connect (GTK_OBJECT (m_Buttons[4]->GetHandle()), "clicked",
GTK_SIGNAL_FUNC (on_button_calltime_clicked),
this);
gtk_box_pack_start (GTK_BOX (hbox), m_Buttons[4]->GetHandle(), TRUE, FALSE, 0);
// 信号连接
gtk_signal_connect (GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC (on_main_window_destroy),
this);
return window;
}
void
CWin::on_main_window_destroy (GtkObject *object,
gpointer user_data)
{
wg_main_quit();
//gtk_main_quit();
}
void
CWin::on_button_dial_clicked (GtkButton *button,
gpointer user_data)
{
CWin* main_win = (CWin*) user_data;
if(!main_win || !(main_win->m_pNotebook))
return;
CNoteBook* pNotebook = main_win->m_pNotebook;
if((pNotebook->GetCurPage() == CNoteBook::detail) &&
(pNotebook->m_Detail->isCallTime()) )
return;
CList* list = pNotebook->m_pList;
int row = list->GetSelectedRow();
if(row < 0)
return ;
gchar* cmd = g_strdup_printf("tel_cal --dial=\"%s%%%s\"",
list->GetTel(row), list->GetName(row));
system(cmd);
g_free(cmd);
}
void
CWin::on_button_save_clicked (GtkButton *button,
gpointer user_data)
{
CWin* main_win = (CWin*) user_data;
if(!main_win || !(main_win->m_pNotebook))
return;
CNoteBook* pNotebook = main_win->m_pNotebook;
if((pNotebook->GetCurPage() == CNoteBook::detail) &&
(pNotebook->m_Detail->isCallTime()) )
return;
CList* list = pNotebook->m_pList;
int row = list->GetSelectedRow();
if(row < 0)
return ;
static int qid = -1;
MSG qbuf;
g_snprintf(qbuf.msg, sizeof(qbuf.msg), "%s%%%s",
list->GetTel(row), list->GetName(row));
if(qid==-1)
qid = open_queue(SEND_MSG_KEY_ID);
if(qid==-1){
g_warning("can not open message queue!");
return;
}
qbuf.mtype = TELE_ID;
qbuf.sender = CALL_INFO_ID;
if(send_msg(qid, &qbuf)==-1)
g_warning("Error occurented while sending to message queue!");
}
void
CWin::on_button_del_clicked (GtkButton *button,
gpointer user_data)
{
CWin* main_win = (CWin*) user_data;
if(!main_win || !(main_win->m_pNotebook))
return;
CNoteBook* pNotebook = main_win->m_pNotebook;
if((pNotebook->GetCurPage() == CNoteBook::detail) &&
(pNotebook->m_Detail->isCallTime()) )
return;
CList* list = pNotebook->m_pList;
int row = list->GetSelectedRow();
if(row < 0)
return ;
if(MessageBox(_("你确认要删除该记录吗?"),
_("删除"), stock_question, MB_Yes|MB_No) == ID_Yes)
{
pNotebook->m_pCif[pNotebook->GetCallType()]->Delete(row);
CCallsInfo::SyncDataFile();
/*
int row = list->GetSelectedRow();
list->Freeze();
list->Clear();
pNotebook->SetCallType(pNotebook->GetCallType(), true);
list->Thaw();
*/
list->RemoveRow(row);
if(pNotebook->GetCurPage() == CNoteBook::detail){
pNotebook->SetPage(CNoteBook::calllist);
}
//list->SelectRow(row);
}
}
void
CWin::on_button_setblack_clicked (GtkButton *button,
gpointer user_data)
{
CWin* main_win = (CWin*) user_data;
if(!main_win || !(main_win->m_pNotebook))
return;
CNoteBook* pNotebook = main_win->m_pNotebook;
if((pNotebook->GetCurPage() == CNoteBook::detail) &&
(pNotebook->m_Detail->isCallTime()) )
return;
if(pNotebook->GetCallType() == 4) // blacklist
return ;
CList* list = pNotebook->m_pList;
int row = list->GetSelectedRow();
if(row < 0)
return;
if(strlen(list->GetTel(row))<=0){
MessageBox(_("无号码不能设为黑名单!"),
_("提示"), stock_info, MB_OK);
return;
}
if(MessageBox(_("你确认要把该电话号码\n列入黑名单吗?"),
_("列入黑名单"), stock_question, MB_Yes|MB_No) == ID_Yes)
{
CCallRecord cr(list->GetName(row), list->GetTel(row));
int ret = pNotebook->m_pCif[4]->NewBlackName(cr);
if(ret == -1)
MessageBox(_("保存数据时出错,\n列入黑名单失败!"),
_("错误"), stock_error, MB_OK);
else if(ret == -2)
MessageBox(_("该号码已经在黑名单中。"),
_("提示"), stock_info, MB_OK);
else
MessageBox(_("列入黑名单成功!"),
_("提示"), stock_info, MB_OK);
CCallsInfo::SyncDataFile();
}
}
void
CWin::on_button_calltime_clicked (GtkButton *button,
gpointer user_data)
{
CWin* main_win = (CWin*) user_data;
if(!main_win || !(main_win->m_pNotebook))
return;
CNoteBook* pNotebook = main_win->m_pNotebook;
pNotebook->ShowDetail(-1);
main_win->m_Buttons[0]->SetSensitive(false);
main_win->m_Buttons[1]->SetSensitive(false);
main_win->m_Buttons[2]->SetSensitive(false);
main_win->m_Buttons[3]->SetSensitive(false);
main_win->m_Buttons[4]->SetSensitive(false);
}
void CWin::on_toolbar_close_button_click(GtkButton *button, gpointer data)
{
CWin* mainwin = (CWin*) data;
if(!mainwin)
return;
CNoteBook* pNotebook = mainwin->m_pNotebook;
if(!pNotebook)
return;
if(pNotebook->GetCurPage() == (int)CNoteBook::detail){
if(pNotebook->m_Detail->isCallTime()){
mainwin->m_Buttons[0]->SetSensitive(true);
mainwin->m_Buttons[1]->SetSensitive(true);
mainwin->m_Buttons[2]->SetSensitive(true);
mainwin->m_Buttons[4]->SetSensitive(true);
}
if(pNotebook->GetCallType() == 4)
mainwin->m_Buttons[3]->SetSensitive(false);
else
mainwin->m_Buttons[3]->SetSensitive(true);
pNotebook->SetPage(CNoteBook::calllist);
gtk_widget_grab_focus(pNotebook->m_pList->GetHandle());
}
else{
GtkWidget* topwin = gtk_widget_get_toplevel (GTK_WIDGET(button));
gtk_widget_destroy(topwin);
}
}
void CWin::on_toolbar_button_pressed(GtkButton *button, gpointer data)
{
CWin* mainwin = (CWin*) data;
if(!mainwin)
return;
int tag = mainwin->m_pToolbar->GetActiveButton()->tag;
mainwin->m_pNotebook->SetCallType(tag);
mainwin->m_pNotebook->SetPage(CNoteBook::calllist);
if(tag == 4){
mainwin->m_Buttons[0]->SetSensitive(true);
mainwin->m_Buttons[1]->SetSensitive(true);
mainwin->m_Buttons[2]->SetSensitive(true);
mainwin->m_Buttons[3]->SetSensitive(false);
mainwin->m_Buttons[4]->SetSensitive(true);
}
else{
mainwin->m_Buttons[0]->SetSensitive(true);
mainwin->m_Buttons[1]->SetSensitive(true);
mainwin->m_Buttons[2]->SetSensitive(true);
mainwin->m_Buttons[3]->SetSensitive(true);
mainwin->m_Buttons[4]->SetSensitive(true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -