Skip to content

Commit

Permalink
Update code style
Browse files Browse the repository at this point in the history
  • Loading branch information
cinience committed Jan 18, 2015
1 parent 156ace9 commit 8daf3dc
Show file tree
Hide file tree
Showing 20 changed files with 198 additions and 154 deletions.
36 changes: 18 additions & 18 deletions RedisStudio/ConnInfoSubWhd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ ConnInfoSubWhd::ConnInfoSubWhd(TDicTables* pDic, bool &needApply, OperatorType t
{
ASSERT(pDic);
m_pdicServerInfo = pDic;
m_celIdx = celIdx;
m_type = type;
m_needApply = &needApply;
m_iCelIdx = celIdx;
m_eType = type;
m_bNeedApply = &needApply;
}

ConnInfoSubWhd::~ConnInfoSubWhd(void)
Expand All @@ -31,21 +31,21 @@ void ConnInfoSubWhd::InitWindow()
m_pEditAuth = static_cast<CEditUI*>(m_PaintManager.FindControl(_T("edt_server_passwd")));
CLabelUI* pLabelAdd = static_cast<CLabelUI*>(m_PaintManager.FindControl(_T("lab_conn_add")));
CLabelUI* pLabelAlt = static_cast<CLabelUI*>(m_PaintManager.FindControl(_T("lab_conn_alt")));
if (m_type == Type_Add)
if (m_eType == Type_Add)
{
pLabelAdd->SetVisible(true);
pLabelAlt->SetVisible(false);
}
else
{
m_pEditName->SetText(Base::CharacterSet::ANSIToUnicode(dicObj[ConnInfoUI::kServerNameIndex][m_celIdx]).c_str());
m_pEditHost->SetText(Base::CharacterSet::ANSIToUnicode(dicObj[ConnInfoUI::kServerIpIndex][m_celIdx]).c_str());
m_pEditPort->SetText(Base::CharacterSet::ANSIToUnicode(dicObj[ConnInfoUI::kServerPortIndex][m_celIdx]).c_str());
m_pEditAuth->SetText(Base::CharacterSet::ANSIToUnicode(dicObj[ConnInfoUI::kServerAuthIndex][m_celIdx]).c_str());
m_pEditName->SetText(Base::CharacterSet::ANSIToUnicode(dicObj[ConnInfoUI::kServerNameIndex][m_iCelIdx]).c_str());
m_pEditHost->SetText(Base::CharacterSet::ANSIToUnicode(dicObj[ConnInfoUI::kServerIpIndex][m_iCelIdx]).c_str());
m_pEditPort->SetText(Base::CharacterSet::ANSIToUnicode(dicObj[ConnInfoUI::kServerPortIndex][m_iCelIdx]).c_str());
m_pEditAuth->SetText(Base::CharacterSet::ANSIToUnicode(dicObj[ConnInfoUI::kServerAuthIndex][m_iCelIdx]).c_str());
pLabelAdd->SetVisible(false);
pLabelAlt->SetVisible(true);
}
*m_needApply = false;
*m_bNeedApply = false;
}

LPCTSTR ConnInfoSubWhd::GetWindowClassName() const
Expand Down Expand Up @@ -88,13 +88,13 @@ void ConnInfoSubWhd::OnClick( TNotifyUI& msg )
if(msg.pSender->GetName() == _T("btn_conn_cancel"))
{
Close();
*m_needApply = false;
*m_bNeedApply = false;
return;
}
else if (msg.pSender->GetName() == _T("btn_conn_save"))
{
bool retVal = false;
if (m_type == Type_Add)
if (m_eType == Type_Add)
{
retVal = OnAddInfo();
}
Expand All @@ -104,11 +104,11 @@ void ConnInfoSubWhd::OnClick( TNotifyUI& msg )
}
if (retVal)
{
*m_needApply = true;
*m_bNeedApply = true;
}
else
{
*m_needApply = false;
*m_bNeedApply = false;
}
Close();
}
Expand Down Expand Up @@ -182,15 +182,15 @@ bool ConnInfoSubWhd::OnAltInfo()
TDicTables& dicObj = *m_pdicServerInfo;
for (std::size_t idx=0; idx<dicObj[ConnInfoUI::kServerNameIndex].size(); ++idx)
{
if (dicObj[ConnInfoUI::kServerNameIndex][idx] == name && idx!=m_celIdx)
if (dicObj[ConnInfoUI::kServerNameIndex][idx] == name && idx!=m_iCelIdx)
{
UserMessageBox(GetHWND(), 10015, NULL, MB_ICONWARNING);
return false;
}
}
dicObj[ConnInfoUI::kServerNameIndex][m_celIdx] = name;
dicObj[ConnInfoUI::kServerIpIndex][m_celIdx] = ip;
dicObj[ConnInfoUI::kServerPortIndex][m_celIdx] = port;
dicObj[ConnInfoUI::kServerAuthIndex][m_celIdx] = auth;
dicObj[ConnInfoUI::kServerNameIndex][m_iCelIdx] = name;
dicObj[ConnInfoUI::kServerIpIndex][m_iCelIdx] = ip;
dicObj[ConnInfoUI::kServerPortIndex][m_iCelIdx] = port;
dicObj[ConnInfoUI::kServerAuthIndex][m_iCelIdx] = auth;
return true;
}
6 changes: 3 additions & 3 deletions RedisStudio/ConnInfoSubWhd.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ class ConnInfoSubWhd : public WindowImplBase
bool OnAltInfo();

private:
bool* m_needApply;
bool* m_bNeedApply;
TDicTables* m_pdicServerInfo;

CEditUI* m_pEditName;
CEditUI* m_pEditHost;
CEditUI* m_pEditPort;
CEditUI* m_pEditAuth;
int m_celIdx;
OperatorType m_type;
int m_iCelIdx;
OperatorType m_eType;
};
22 changes: 20 additions & 2 deletions RedisStudio/ConnInfoUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,26 @@ ConnInfoUI::ConnInfoUI(const CDuiString& strXML,CPaintManagerUI* pm, Environment
}
}

ConnInfoUI::~ConnInfoUI()
{
if (m_Thread.isRunning())
{
m_Event.set();
}

while (m_Thread.isRunning())
{
Base::Thread::sleep(100);
}

DBClient* cli = Env()->GetDBClient();
if (cli)
{
delete cli;
Env()->SetDBClient(NULL);
}
}

void ConnInfoUI::Initialize()
{
m_pRfhBtn = static_cast<CButtonUI*>(GetPaintMgr()->FindControl(_T("btn_conn_rfh")));
Expand Down Expand Up @@ -297,8 +317,6 @@ void ConnInfoUI::BackgroundWork( void )
CDuiString* s = new CDuiString(Env()->GetDBName());
::PostMessage(GetHWND(), WM_USER_CONNECTING, (WPARAM)s, NULL);



DBClient *cli = DBClient::Create(Env()->GetDBIP(), Env()->GetDBPort(), Env()->GetDBPasswd());
if (cli && cli->IsConnected())
{
Expand Down
2 changes: 2 additions & 0 deletions RedisStudio/ConnInfoUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class ConnInfoUI : public AbstraceUI,public IListCallbackUI
public:
ConnInfoUI(const CDuiString& strXML, CPaintManagerUI* pm, Environment* env);

~ConnInfoUI();

void Initialize();

int GetIndex();
Expand Down
29 changes: 22 additions & 7 deletions RedisStudio/Environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "Environment.h"
#include "DBClient.h"

Environment::Environment():m_DbClient(NULL)
Environment::Environment():m_DbClient(NULL),m_ConnIdx(0)
{
}

Expand All @@ -13,42 +13,57 @@ Environment::~Environment()

void Environment::SetDBClient(DBClient* cli)
{
Base::Mutex::ScopedLock scopedLock(m_Mutex);
m_DbClient = cli;
m_ConnIdx++;
}

DBClient* Environment::GetDBClient()
{
Base::Mutex::ScopedLock scopedLock(m_Mutex);
return m_DbClient;
}

int Environment::GetDBIdx()
{
Base::Mutex::ScopedLock scopedLock(m_Mutex);
return m_ConnIdx;
}

void Environment::SetDBName(const CDuiString& name)
{
Base::Mutex::ScopedLock scopedLock(m_Mutex);
m_DbName = name;
}

DuiLib::CDuiString Environment::GetDBName()
{
Base::Mutex::ScopedLock scopedLock(m_Mutex);
return m_DbName;
}

void Environment::SetDBServerInfo(const std::string& addr, int port, const std::string& auth/*=""*/)
{
m_sIP = addr;
m_iPort = port;
m_sAuth = auth;
Base::Mutex::ScopedLock scopedLock(m_Mutex);
m_IP = addr;
m_Port = port;
m_Auth = auth;
}

std::string Environment::GetDBIP()
{
return m_sIP;
Base::Mutex::ScopedLock scopedLock(m_Mutex);
return m_IP;
}

int Environment::GetDBPort()
{
return m_iPort;
Base::Mutex::ScopedLock scopedLock(m_Mutex);
return m_Port;
}

std::string Environment::GetDBPasswd()
{
return m_sAuth;
Base::Mutex::ScopedLock scopedLock(m_Mutex);
return m_Auth;
}
12 changes: 9 additions & 3 deletions RedisStudio/Environment.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include "Base/Mutex.h"

class DBClient;

class Environment {
Expand All @@ -16,6 +18,8 @@ class Environment {

DBClient* GetDBClient();

int GetDBIdx();

CDuiString GetDBName();

std::string GetDBIP();
Expand All @@ -26,8 +30,10 @@ class Environment {

private:
CDuiString m_DbName;
std::string m_sIP;
int m_iPort;
std::string m_sAuth;
std::string m_IP;
int m_Port;
std::string m_Auth;
DBClient* m_DbClient;
Base::Mutex m_Mutex;
int m_ConnIdx;
};
24 changes: 12 additions & 12 deletions RedisStudio/MainFrameWhd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ CMainFrameWnd::CMainFrameWnd()

CMainFrameWnd::~CMainFrameWnd()
{
for (int idx=0; idx<m_TabContainer.GetSize(); ++idx)
for (int idx=0; idx<m_oTabContainer.GetSize(); ++idx)
{
RemoveVirtualWnd(m_TabContainer[idx]);
RemoveVirtualWnd(m_oTabContainer[idx]);
}
}

Expand Down Expand Up @@ -70,16 +70,16 @@ void CMainFrameWnd::InitWindow()
theMsg.Replace(_T("$version"), _T(VERSION));
m_pVersionControl->SetText(theMsg);

for (int idx=0; idx<m_TabContainer.GetSize(); ++idx)
for (int idx=0; idx<m_oTabContainer.GetSize(); ++idx)
{
AbstraceUI* p = (AbstraceUI*)m_TabContainer.Find(m_TabContainer[idx]);
AbstraceUI* p = (AbstraceUI*)m_oTabContainer.Find(m_oTabContainer[idx]);
p->Initialize();

}
/// 刷新默认窗口加载数据
for (int idx=0; idx<m_TabContainer.GetSize(); ++idx)
for (int idx=0; idx<m_oTabContainer.GetSize(); ++idx)
{
AbstraceUI* p = (AbstraceUI*)m_TabContainer.Find(m_TabContainer[idx]);
AbstraceUI* p = (AbstraceUI*)m_oTabContainer.Find(m_oTabContainer[idx]);
if (p->GetIndex() == 0)
{
p->RefreshWnd();
Expand Down Expand Up @@ -177,7 +177,7 @@ CControlUI* CMainFrameWnd::CreateControl(LPCTSTR pstrClassName)
{
AddVirtualWnd(p->GetVirtualwndName(), p);
p->SetHWND(GetHWND());
m_TabContainer.Set(p->GetVirtualwndName(), p);
m_oTabContainer.Set(p->GetVirtualwndName(), p);
return p;
}
return NULL;
Expand Down Expand Up @@ -242,11 +242,11 @@ void CMainFrameWnd::OnSelectChanged( TNotifyUI &msg )
static AbstraceUI* pLastTab = NULL;
AbstraceUI* p = NULL;
/// 除了tab的按钮的消息外,还有其它消息,所以此处只判断tab相关的消息
for (int idx=0; idx<m_TabContainer.GetSize(); ++idx)
for (int idx=0; idx<m_oTabContainer.GetSize(); ++idx)
{
if (name == m_TabContainer[idx])
if (name == m_oTabContainer[idx])
{
p = (AbstraceUI*)m_TabContainer.Find(name);
p = (AbstraceUI*)m_oTabContainer.Find(name);
}
}
if (p == NULL) return;
Expand Down Expand Up @@ -417,9 +417,9 @@ LRESULT CMainFrameWnd::HandleCustomMessage( UINT uMsg, WPARAM wParam, LPARAM lPa
}
if (!bHandled)
{
for (int idx=0; idx<m_TabContainer.GetSize(); ++idx)
for (int idx=0; idx<m_oTabContainer.GetSize(); ++idx)
{
AbstraceUI* p = (AbstraceUI*)m_TabContainer.Find(m_TabContainer[idx]);
AbstraceUI* p = (AbstraceUI*)m_oTabContainer.Find(m_oTabContainer[idx]);
p->HandleCustomMessage(uMsg, wParam, lParam, bHandled);
}
}
Expand Down
2 changes: 1 addition & 1 deletion RedisStudio/MainFrameWhd.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ class CMainFrameWnd : public WindowImplBase
CTextUI* m_pConnectingControl ;
CTextUI* m_pVersionControl;

CStdStringPtrMap m_TabContainer;
CStdStringPtrMap m_oTabContainer;
Environment m_pEnv;
};
Loading

0 comments on commit 8daf3dc

Please sign in to comment.