Alarm browser improved
authorVictor Kirhenshtein <victor@netxms.org>
Tue, 24 Jul 2007 15:33:21 +0000 (15:33 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Tue, 24 Jul 2007 15:33:21 +0000 (15:33 +0000)
src/client/console/include/nxmc_api.h
src/client/console/libnxmc/tools.cpp
src/client/console/plugins/AlarmBrowser/alarm_browser.h
src/client/console/plugins/AlarmBrowser/browser.cpp
src/client/console/plugins/AlarmBrowser/view.cpp

index de94a44..7cb7ec2 100644 (file)
@@ -332,4 +332,7 @@ void LIBNXMC_EXPORTABLE NXMCUnlockAlarmList();
 
 TCHAR LIBNXMC_EXPORTABLE *NXMCFormatTimeStamp(time_t timeStamp, TCHAR *buffer, int type);
 
+void LIBNXMC_EXPORTABLE NXMCSaveListCtrlColumns(wxConfigBase *cfg, wxListCtrl &wndListCtrl, const TCHAR *prefix);
+void LIBNXMC_EXPORTABLE NXMCLoadListCtrlColumns(wxConfigBase *cfg, wxListCtrl &wndListCtrl, const TCHAR *prefix);
+
 #endif
index 4963663..7c2de82 100644 (file)
@@ -103,3 +103,49 @@ bool LIBNXMC_EXPORTABLE NXMCLoadResources(const TCHAR *name, NXMC_LIB_INSTANCE i
        wxLogDebug(_T("Loading resource file %s"), xrsFile.c_str());
        return wxXmlResource::Get()->Load(xrsFile);
 }
+
+
+//
+// Save dimensions of all list control columns into config
+//
+
+void LIBNXMC_EXPORTABLE NXMCSaveListCtrlColumns(wxConfigBase *cfg, wxListCtrl &wndListCtrl, const TCHAR *prefix)
+{
+   int i, count;
+       wxString path = cfg->GetPath();
+   TCHAR item[64];
+
+       cfg->SetPath(prefix);
+       count = wndListCtrl.GetColumnCount();
+       cfg->Write(_T("ColumnCount"), count);
+       for(i = 0; i < count; i++)
+   {
+      _stprintf(item, _T("Column%d"), i);
+               cfg->Write(item, wndListCtrl.GetColumnWidth(i));
+   }
+       cfg->SetPath(path);
+}
+
+
+//
+// Load and set dimensions of all list control columns
+//
+
+void LIBNXMC_EXPORTABLE NXMCLoadListCtrlColumns(wxConfigBase *cfg, wxListCtrl &wndListCtrl, const TCHAR *prefix)
+{
+   long i, count, width;
+       wxString path = cfg->GetPath();
+   TCHAR item[64];
+
+       cfg->SetPath(prefix);
+       cfg->Read(_T("ColumnCount"), &count, 0);
+
+   for(i = 0; i < count; i++)
+   {
+      _stprintf(item, _T("Column%d"), i);
+               cfg->Read(item, &width, 50);
+      wndListCtrl.SetColumnWidth(i, width);
+   }
+
+       cfg->SetPath(path);
+}
index dbab455..06ac9d4 100644 (file)
@@ -40,12 +40,15 @@ private:
        wxListView *m_wndListCtrl;
        long m_sortMode;
        long m_sortDir;
+       wxString m_context;
 
        void AddAlarm(NXC_ALARM *alarm);
        void UpdateAlarm(long item, NXC_ALARM *alarm);
+       void SortAlarmList();
 
 public:
-       nxAlarmView(wxWindow *parent);
+       nxAlarmView(wxWindow *parent, const TCHAR *context);
+       virtual ~nxAlarmView();
 
        void RefreshView();
 
index c805d0f..85e8e9f 100644 (file)
@@ -45,7 +45,7 @@ nxAlarmBrowser::nxAlarmBrowser()
        SetLabel(_T("Alarm Browser"));
        RegisterUniqueView(_T("alarmbrowser"), this);
 
-       m_view = new nxAlarmView(this);
+       m_view = new nxAlarmView(this, _T("/AlarmBrowser"));
 
        wxCommandEvent event(nxEVT_REFRESH_VIEW);
        AddPendingEvent(event);
index 479f74e..dceb71e 100644 (file)
@@ -39,11 +39,17 @@ END_EVENT_TABLE()
 // Constructor
 //
 
-nxAlarmView::nxAlarmView(wxWindow *parent)
+nxAlarmView::nxAlarmView(wxWindow *parent, const TCHAR *context)
             : wxWindow(parent, wxID_ANY)
 {
-       wxConfig::Get()->Read(_T("/AlarmView/SortMode"), &m_sortMode, 0);
-       wxConfig::Get()->Read(_T("/AlarmView/SortDir"), &m_sortDir, -1);
+       wxConfigBase *cfg = wxConfig::Get();
+       wxString path = cfg->GetPath();
+
+       m_context = context;
+
+       cfg->SetPath(m_context);
+       cfg->Read(_T("AlarmView/SortMode"), &m_sortMode, 0);
+       cfg->Read(_T("AlarmView/SortDir"), &m_sortDir, -1);
 
        m_wndListCtrl = new wxListView(this, wxID_LIST_CTRL, wxDefaultPosition, wxDefaultSize,
                                       wxLC_REPORT | wxLC_HRULES | wxLC_VRULES);
@@ -61,6 +67,26 @@ nxAlarmView::nxAlarmView(wxWindow *parent)
        imgList->Add(wxXmlResource::Get()->LoadIcon(_T("icoSortUp")));
        imgList->Add(wxXmlResource::Get()->LoadIcon(_T("icoSortDown")));
        m_wndListCtrl->AssignImageList(imgList, wxIMAGE_LIST_SMALL);
+       NXMCLoadListCtrlColumns(cfg, *m_wndListCtrl, _T("AlarmView"));
+
+       cfg->SetPath(path);
+}
+
+
+//
+// Destructor
+//
+
+nxAlarmView::~nxAlarmView()
+{
+       wxConfigBase *cfg = wxConfig::Get();
+       wxString path = cfg->GetPath();
+
+       cfg->SetPath(m_context);
+       cfg->Write(_T("AlarmView/SortMode"), m_sortMode);
+       cfg->Write(_T("AlarmView/SortDir"), m_sortDir);
+       NXMCSaveListCtrlColumns(cfg, *m_wndListCtrl, _T("AlarmView"));
+       cfg->SetPath(path);
 }
 
 
@@ -93,6 +119,8 @@ void nxAlarmView::RefreshView()
        }
 
        NXMCUnlockAlarmList();
+
+       SortAlarmList();
 }
 
 
@@ -173,6 +201,7 @@ static int wxCALLBACK CompareAlarms(long item1, long item2, long sortData)
        long mode = sortData & 0x7FFF;
        int rc;
        nxAlarmList::iterator it1, it2;
+       NXC_OBJECT *obj1, *obj2;
 
        it1 = s_alarmList->find(item1);
        it2 = s_alarmList->find(item2);
@@ -190,9 +219,23 @@ static int wxCALLBACK CompareAlarms(long item1, long item2, long sortData)
                case 1:         // State
                        rc = COMPARE_NUMBERS(it1->second->nState, it2->second->nState);
                        break;
+               case 2:         // Source
+                       obj1 = NXCFindObjectById(NXMCGetSession(), it1->second->dwSourceObject);
+                       obj2 = NXCFindObjectById(NXMCGetSession(), it2->second->dwSourceObject);
+                       rc = _tcsicmp((obj1 != NULL) ? obj1->szName : _T("(null)"), (obj2 != NULL) ? obj2->szName : _T("(null)"));
+                       break;
                case 3:         // Message
                        rc = _tcsicmp(it1->second->szMessage, it2->second->szMessage);
                        break;
+               case 4:         // Count
+                       rc = COMPARE_NUMBERS(it1->second->dwRepeatCount, it2->second->dwRepeatCount);
+                       break;
+               case 5:         // Created
+                       rc = COMPARE_NUMBERS(it1->second->dwCreationTime, it2->second->dwCreationTime);
+                       break;
+               case 6:         // Last changed
+                       rc = COMPARE_NUMBERS(it1->second->dwLastChangeTime, it2->second->dwLastChangeTime);
+                       break;
                default:
                        rc = 0;
                        break;
@@ -202,6 +245,21 @@ static int wxCALLBACK CompareAlarms(long item1, long item2, long sortData)
 }
 
 
+//
+// Sort aarm list
+//
+
+void nxAlarmView::SortAlarmList()
+{
+       s_alarmList = NXMCGetAlarmList();
+       m_wndListCtrl->SortItems(CompareAlarms, m_sortMode | ((m_sortDir == 1) ? 0x8000 : 0));
+       NXMCUnlockAlarmList();
+
+       // Mark sorting column
+       m_wndListCtrl->SetColumnImage(m_sortMode, STATUS_TESTING + ((m_sortDir == 1) ? 4 : 5));
+}
+
+
 //
 // Handler for column click
 //
@@ -218,10 +276,5 @@ void nxAlarmView::OnListColumnClick(wxListEvent &event)
        {
                m_sortMode = event.GetColumn();
        }
-
-       s_alarmList = NXMCGetAlarmList();
-       m_wndListCtrl->SortItems(CompareAlarms, m_sortMode | ((m_sortDir == 1) ? 0x8000 : 0));
-       NXMCUnlockAlarmList();
-
-       m_wndListCtrl->SetColumnImage(m_sortMode, STATUS_TESTING + ((m_sortDir == 1) ? 4 : 5));
+       SortAlarmList();
 }