summaryrefslogtreecommitdiff
path: root/plugins/NewsAggregator
diff options
context:
space:
mode:
authorKirill Volinsky <mataes2007@gmail.com>2013-01-06 18:32:12 +0000
committerKirill Volinsky <mataes2007@gmail.com>2013-01-06 18:32:12 +0000
commit97b13834eec468cfceeb43cbe1eeef944f2de7bc (patch)
treec20e17b364aefb95f20f41889b16b3db46a1b0e0 /plugins/NewsAggregator
parentf416a25cafc951228dd12b22af0ac53b4fb7d68f (diff)
added main menu item for disabling auto update (needs to add icons)
git-svn-id: http://svn.miranda-ng.org/main/trunk@2999 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/NewsAggregator')
-rw-r--r--plugins/NewsAggregator/Src/Common.h25
-rw-r--r--plugins/NewsAggregator/Src/Menus.cpp42
-rw-r--r--plugins/NewsAggregator/Src/NewsAggregator.cpp3
-rw-r--r--plugins/NewsAggregator/Src/Services.cpp44
-rw-r--r--plugins/NewsAggregator/Src/Utils.cpp91
5 files changed, 121 insertions, 84 deletions
diff --git a/plugins/NewsAggregator/Src/Common.h b/plugins/NewsAggregator/Src/Common.h
index 059a732e42..cb4f99e5a2 100644
--- a/plugins/NewsAggregator/Src/Common.h
+++ b/plugins/NewsAggregator/Src/Common.h
@@ -82,6 +82,7 @@ void UpdateThreadProc(LPVOID hWnd);
void DestroyUpdateList(void);
extern HANDLE hUpdateMutex;
+extern HANDLE hService2[7];
int NewsAggrInit(WPARAM wParam,LPARAM lParam);
INT OptInit(WPARAM wParam, LPARAM lParam);
@@ -99,14 +100,15 @@ INT_PTR NewsAggrGetStatus(WPARAM/* wp*/, LPARAM/* lp*/);
INT_PTR NewsAggrLoadIcon(WPARAM wParam, LPARAM lParam);
INT_PTR NewsAggrGetInfo(WPARAM wParam, LPARAM lParam);
INT_PTR NewsAggrGetAvatarInfo(WPARAM wParam, LPARAM lParam);
-INT_PTR NewsAggrRecvMessage(WPARAM wParam,LPARAM lParam);
-
-INT_PTR CheckAllFeeds(WPARAM wParam,LPARAM lParam);
-INT_PTR AddFeed(WPARAM wParam,LPARAM lParam);
-INT_PTR ChangeFeed(WPARAM wParam,LPARAM lParam);
-INT_PTR ImportFeeds(WPARAM wParam,LPARAM lParam);
-INT_PTR ExportFeeds(WPARAM wParam,LPARAM lParam);
-INT_PTR CheckFeed(WPARAM wParam,LPARAM lParam);
+INT_PTR NewsAggrRecvMessage(WPARAM wParam, LPARAM lParam);
+
+INT_PTR CheckAllFeeds(WPARAM wParam, LPARAM lParam);
+INT_PTR AddFeed(WPARAM wParam, LPARAM lParam);
+INT_PTR ChangeFeed(WPARAM wParam, LPARAM lParam);
+INT_PTR ImportFeeds(WPARAM wParam, LPARAM lParam);
+INT_PTR ExportFeeds(WPARAM wParam, LPARAM lParam);
+INT_PTR CheckFeed(WPARAM wParam, LPARAM lParam);
+INT_PTR EnableDisable(WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK DlgProcAddFeedOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK DlgProcChangeFeedOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK DlgProcChangeFeedMenu(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
@@ -121,6 +123,7 @@ VOID DeleteAllItems(HWND hwndList);
time_t __stdcall DateToUnixTime(TCHAR *stamp, BOOL FeedType);
VOID CheckCurrentFeed (HANDLE hContact);
TCHAR* CheckFeed(TCHAR* tszURL, HWND hwndDlg);
+void UpdateMenu(BOOL State);
// =============== NewsAggregator SERVICES ================
// Check all Feeds info
@@ -145,4 +148,8 @@ TCHAR* CheckFeed(TCHAR* tszURL, HWND hwndDlg);
// Check Feed info
// WPARAM = LPARAM = NULL
-#define MS_NEWSAGGREGATOR_CHECKFEED "NewsAggregator/CheckFeed" \ No newline at end of file
+#define MS_NEWSAGGREGATOR_CHECKFEED "NewsAggregator/CheckFeed"
+
+// Check Feed info
+// WPARAM = LPARAM = NULL
+#define MS_NEWSAGGREGATOR_ENABLED "NewsAggregator/Enabled" \ No newline at end of file
diff --git a/plugins/NewsAggregator/Src/Menus.cpp b/plugins/NewsAggregator/Src/Menus.cpp
index 7ddd0c8a07..66c72a8dcb 100644
--- a/plugins/NewsAggregator/Src/Menus.cpp
+++ b/plugins/NewsAggregator/Src/Menus.cpp
@@ -19,59 +19,67 @@ Boston, MA 02111-1307, USA.
#include "common.h"
-HANDLE hService2[6];
+HANDLE hService2[7];
VOID InitMenu()
{
CLISTMENUITEM mi = { sizeof(mi) };
mi.pszContactOwner = MODULE;
- mi.flags = CMIF_TCHAR|CMIF_ICONFROMICOLIB|CMIF_NOTOFFLINE;
+ mi.flags = CMIF_TCHAR | CMIF_ICONFROMICOLIB | CMIF_NOTOFFLINE;
// adding main menu items
mi.ptszPopupName = LPGENT("News Aggregator");
mi.popupPosition = 500099000;
- mi.position=10100001;
+ mi.position = 10100001;
+ if (db_get_b(NULL, MODULE, "AutoUpdate", 1))
+ mi.ptszName = LPGENT("Auto Update Enabled");
+ else
+ mi.ptszName = LPGENT("Auto Update Disabled");
mi.icolibItem = GetIconHandle("main");
+ mi.pszService = MS_NEWSAGGREGATOR_ENABLED;
+ hService2[0] = Menu_AddMainMenuItem(&mi);
+
+ mi.position = 20100001;
mi.ptszName = LPGENT("Check All Feeds");
mi.pszService = MS_NEWSAGGREGATOR_CHECKALLFEEDS;
- hService2[0] = Menu_AddMainMenuItem(&mi);
+ hService2[1] = Menu_AddMainMenuItem(&mi);
- mi.position=10100002;
+ mi.position = 20100002;
mi.icolibItem = GetIconHandle("addfeed");
mi.ptszName = LPGENT("Add Feed");
mi.pszService = MS_NEWSAGGREGATOR_ADDFEED;
- hService2[1] = Menu_AddMainMenuItem(&mi);
+ hService2[2] = Menu_AddMainMenuItem(&mi);
- mi.position=10100003;
+ mi.position = 20100003;
mi.icolibItem = GetIconHandle("importfeeds");
mi.ptszName = LPGENT("Import Feeds");
mi.pszService = MS_NEWSAGGREGATOR_IMPORTFEEDS;
- hService2[2] = Menu_AddMainMenuItem(&mi);
+ hService2[3] = Menu_AddMainMenuItem(&mi);
- mi.position=10100004;
+ mi.position = 20100004;
mi.icolibItem = GetIconHandle("exportfeeds");
mi.ptszName = LPGENT("Export Feeds");
mi.pszService = MS_NEWSAGGREGATOR_EXPORTFEEDS;
- hService2[3] = Menu_AddMainMenuItem(&mi);
+ hService2[4] = Menu_AddMainMenuItem(&mi);
// adding contact menu items
- mi.position=-0x7FFFFFFA;
+ mi.position = -0x7FFFFFFA;
mi.icolibItem = GetIconHandle("checkfeed");
mi.ptszName = LPGENT("Check feed");
mi.pszService = MS_NEWSAGGREGATOR_CHECKFEED;
- hService2[4] = Menu_AddContactMenuItem(&mi);
+ hService2[5] = Menu_AddContactMenuItem(&mi);
- // adding contact menu items
- mi.position=-0x7FFFFFFA;
- //mi.icolibItem = GetIconHandle("checkfeed");
mi.ptszName = LPGENT("Change feed");
mi.pszService = MS_NEWSAGGREGATOR_CHANGEFEED;
- hService2[5] = Menu_AddContactMenuItem(&mi);
+ hService2[6] = Menu_AddContactMenuItem(&mi);
ZeroMemory(&mi, sizeof(mi));
mi.cbSize = sizeof(mi);
mi.flags = CMIM_ICON;
- mi.icolibItem = GetIconHandle("checkall");
+ if (db_get_b(NULL, MODULE, "AutoUpdate", 1))
+ mi.icolibItem = GetIconHandle("enabled");
+ else
+ mi.icolibItem = GetIconHandle("disabled");
CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hService2[0], (LPARAM)&mi);
} \ No newline at end of file
diff --git a/plugins/NewsAggregator/Src/NewsAggregator.cpp b/plugins/NewsAggregator/Src/NewsAggregator.cpp
index a1d62bf90b..141052d60d 100644
--- a/plugins/NewsAggregator/Src/NewsAggregator.cpp
+++ b/plugins/NewsAggregator/Src/NewsAggregator.cpp
@@ -29,7 +29,7 @@ HANDLE hChangeFeedDlgList = NULL;
XML_API xi = {0};
TCHAR tszRoot[MAX_PATH] = {0};
HANDLE hUpdateMutex;
-#define NUM_SERVICES 6
+#define NUM_SERVICES 7
HANDLE hService[NUM_SERVICES];
PLUGININFOEX pluginInfoEx = {
@@ -106,6 +106,7 @@ extern "C" __declspec(dllexport) int Load(void)
hService[3] = CreateServiceFunction(MS_NEWSAGGREGATOR_EXPORTFEEDS, ExportFeeds);
hService[4] = CreateServiceFunction(MS_NEWSAGGREGATOR_CHECKFEED, CheckFeed);
hService[5] = CreateServiceFunction(MS_NEWSAGGREGATOR_CHANGEFEED, ChangeFeed);
+ hService[6] = CreateServiceFunction(MS_NEWSAGGREGATOR_ENABLED, EnableDisable);
return 0;
}
diff --git a/plugins/NewsAggregator/Src/Services.cpp b/plugins/NewsAggregator/Src/Services.cpp
index 72f666fa98..cecba97960 100644
--- a/plugins/NewsAggregator/Src/Services.cpp
+++ b/plugins/NewsAggregator/Src/Services.cpp
@@ -19,13 +19,13 @@ Boston, MA 02111-1307, USA.
#include "common.h"
-int g_nStatus = ID_STATUS_OFFLINE;
+int g_nStatus = ID_STATUS_ONLINE;
UINT_PTR timerId = 0;
-void SetContactStatus(HANDLE hContact,int nNewStatus)
+void SetContactStatus(HANDLE hContact, int nNewStatus)
{
- if(DBGetContactSettingWord(hContact,MODULE,"Status",ID_STATUS_OFFLINE) != nNewStatus)
- DBWriteContactSettingWord(hContact,MODULE,"Status",nNewStatus);
+ if(DBGetContactSettingWord(hContact, MODULE, "Status", ID_STATUS_ONLINE) != nNewStatus)
+ DBWriteContactSettingWord(hContact, MODULE, "Status", nNewStatus);
}
static void __cdecl WorkingThread(void* param)
@@ -43,14 +43,14 @@ static void __cdecl WorkingThread(void* param)
}
}
-int NewsAggrInit(WPARAM wParam,LPARAM lParam)
+int NewsAggrInit(WPARAM wParam, LPARAM lParam)
{
- HANDLE hContact= db_find_first();
+ HANDLE hContact = db_find_first();
while (hContact != NULL)
{
if(IsMyContact(hContact))
{
- SetContactStatus(hContact, ID_STATUS_OFFLINE);
+ SetContactStatus(hContact, ID_STATUS_ONLINE);
}
hContact = db_find_next(hContact);
}
@@ -72,7 +72,6 @@ int NewsAggrPreShutdown(WPARAM wParam,LPARAM lParam)
}
WindowList_Broadcast(hChangeFeedDlgList, WM_CLOSE, 0, 0);
- mir_forkthread(WorkingThread, (void*)ID_STATUS_OFFLINE);
KillTimer(NULL, timerId);
NetlibUnInit();
@@ -112,7 +111,7 @@ INT_PTR NewsAggrGetCaps(WPARAM wp,LPARAM lp)
}
}
-INT_PTR NewsAggrSetStatus(WPARAM wp,LPARAM /*lp*/)
+INT_PTR NewsAggrSetStatus(WPARAM wp, LPARAM /*lp*/)
{
int nStatus = wp;
if ((ID_STATUS_ONLINE == nStatus) || (ID_STATUS_OFFLINE == nStatus))
@@ -242,4 +241,29 @@ INT_PTR NewsAggrRecvMessage(WPARAM wParam, LPARAM lParam)
{
CallService(MS_PROTO_RECVMSG, 0, lParam);
return 0;
-} \ No newline at end of file
+}
+
+void UpdateMenu(BOOL State)
+{
+ CLISTMENUITEM mi = { sizeof(mi) };
+
+ if (!State) { // to enable auto-update
+ mi.ptszName = LPGENT("Auto Update Enabled");
+ mi.icolibItem = GetIconHandle("enabled");
+ }
+ else { // to disable auto-update
+ mi.ptszName = LPGENT("Auto Update Disabled");
+ mi.icolibItem = GetIconHandle("disabled");
+ }
+
+ mi.flags = CMIM_ICON | CMIM_NAME | CMIF_ICONFROMICOLIB | CMIF_TCHAR;
+ CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hService2[0], (LPARAM)&mi);
+ db_set_b(NULL, MODULE, "AutoUpdate", !State);
+}
+
+// update the newsaggregator auto-update menu item when click on it
+INT_PTR EnableDisable(WPARAM wParam, LPARAM lParam)
+{
+ UpdateMenu(db_get_b(NULL, MODULE, "AutoUpdate", 1));
+ return 0;
+}
diff --git a/plugins/NewsAggregator/Src/Utils.cpp b/plugins/NewsAggregator/Src/Utils.cpp
index 490f8d2464..50aa1edefa 100644
--- a/plugins/NewsAggregator/Src/Utils.cpp
+++ b/plugins/NewsAggregator/Src/Utils.cpp
@@ -722,67 +722,64 @@ TCHAR* CheckFeed(TCHAR* tszURL, HWND hwndDlg)
{
char *szData = NULL;
DBVARIANT dbVar = {0};
- if (CallProtoService(MODULE, PS_GETSTATUS, 0, 0) != ID_STATUS_OFFLINE)
+ GetNewsData(tszURL, &szData, NULL, hwndDlg);
+ if (szData)
{
- GetNewsData(tszURL, &szData, NULL, hwndDlg);
- if (szData)
+ TCHAR *tszData = mir_utf8decodeT(szData);
+ if (!tszData)
+ tszData = mir_a2t(szData);
+ int bytesParsed = 0;
+ HXML hXml = xi.parseString(tszData, &bytesParsed, NULL);
+ mir_free(tszData);
+ mir_free(szData);
+ if (hXml != NULL)
{
- TCHAR *tszData = mir_utf8decodeT(szData);
- if (!tszData)
- tszData = mir_a2t(szData);
- int bytesParsed = 0;
- HXML hXml = xi.parseString(tszData, &bytesParsed, NULL);
- mir_free(tszData);
- mir_free(szData);
- if (hXml != NULL)
+ int childcount = 0;
+ HXML node = xi.getChild(hXml, childcount);
+ while (node)
{
- int childcount = 0;
- HXML node = xi.getChild(hXml, childcount);
- while (node)
+ if (!lstrcmpi(xi.getName(node), _T("rss")) || !lstrcmpi(xi.getName(node), _T("rdf")))
{
- if (!lstrcmpi(xi.getName(node), _T("rss")) || !lstrcmpi(xi.getName(node), _T("rdf")))
+ HXML chan = xi.getChild(node, 0);
+ for (int j = 0; j < xi.getChildCount(chan); j++)
{
- HXML chan = xi.getChild(node, 0);
- for (int j = 0; j < xi.getChildCount(chan); j++)
+ HXML child = xi.getChild(chan, j);
+ if (!lstrcmpi(xi.getName(child), _T("title")))
{
- HXML child = xi.getChild(chan, j);
- if (!lstrcmpi(xi.getName(child), _T("title")))
- {
- TCHAR mes[MAX_PATH];
- mir_sntprintf(mes, SIZEOF(mes), TranslateT("%s\nis a valid feed's address."), tszURL);
- MessageBox(NULL, mes, TranslateT("New Aggregator"), MB_OK|MB_ICONINFORMATION);
- TCHAR *tszTitle = (TCHAR*)xi.getText(child);
- return tszTitle;
- }
+ TCHAR mes[MAX_PATH];
+ mir_sntprintf(mes, SIZEOF(mes), TranslateT("%s\nis a valid feed's address."), tszURL);
+ MessageBox(NULL, mes, TranslateT("New Aggregator"), MB_OK|MB_ICONINFORMATION);
+ TCHAR *tszTitle = (TCHAR*)xi.getText(child);
+ return tszTitle;
}
}
- else if (!lstrcmpi(xi.getName(node), _T("feed")))
+ }
+ else if (!lstrcmpi(xi.getName(node), _T("feed")))
+ {
+ for (int j = 0; j < xi.getChildCount(node); j++)
{
- for (int j = 0; j < xi.getChildCount(node); j++)
+ HXML child = xi.getChild(node, j);
+ if (!lstrcmpi(xi.getName(child), _T("title")))
{
- HXML child = xi.getChild(node, j);
- if (!lstrcmpi(xi.getName(child), _T("title")))
- {
- TCHAR mes[MAX_PATH];
- mir_sntprintf(mes, SIZEOF(mes), TranslateT("%s\nis a valid feed's address."), tszURL);
- MessageBox(NULL, mes, TranslateT("New Aggregator"), MB_OK|MB_ICONINFORMATION);
- TCHAR *tszTitle = (TCHAR*)xi.getText(child);
- return tszTitle;
- }
+ TCHAR mes[MAX_PATH];
+ mir_sntprintf(mes, SIZEOF(mes), TranslateT("%s\nis a valid feed's address."), tszURL);
+ MessageBox(NULL, mes, TranslateT("New Aggregator"), MB_OK|MB_ICONINFORMATION);
+ TCHAR *tszTitle = (TCHAR*)xi.getText(child);
+ return tszTitle;
}
}
- childcount +=1;
- node = xi.getChild(hXml, childcount);
}
+ childcount +=1;
+ node = xi.getChild(hXml, childcount);
}
- xi.destroyNode(hXml);
- }
- else
- {
- TCHAR mes[MAX_PATH];
- mir_sntprintf(mes, SIZEOF(mes), TranslateT("%s\nis a not valid feed's address."), tszURL);
- MessageBox(NULL, mes, TranslateT("New Aggregator"), MB_OK|MB_ICONERROR);
}
+ xi.destroyNode(hXml);
+ }
+ else
+ {
+ TCHAR mes[MAX_PATH];
+ mir_sntprintf(mes, SIZEOF(mes), TranslateT("%s\nis a not valid feed's address."), tszURL);
+ MessageBox(NULL, mes, TranslateT("New Aggregator"), MB_OK|MB_ICONERROR);
}
return NULL;
}
@@ -793,7 +790,7 @@ VOID CheckCurrentFeed(HANDLE hContact)
DBVARIANT dbURL = {0};
if (DBGetContactSettingTString(hContact, MODULE, "URL", &dbURL))
return;
- else if ((DBGetContactSettingWord(hContact, MODULE, "Status", ID_STATUS_OFFLINE) != ID_STATUS_OFFLINE) && DBGetContactSettingByte(hContact, MODULE, "CheckState", 1) != 0)
+ else if (db_get_b(NULL, MODULE, "AutoUpdate", 1) != 0 && db_get_b(hContact, MODULE, "CheckState", 1) != 0)
{
GetNewsData(dbURL.ptszVal, &szData, hContact, NULL);
DBFreeVariant(&dbURL);