/*
Project : RSS Reader plugin for Internet Explorer
File Name : RRPConfigurationDialog.cpp
Date :
Purpose : It contains the code for the settings dialog box which is used to change
the settings of the rss reader
Note :
Send comments
or Bugs to : prafulla_t@users.sourceforge.net
*/
#include "stdafx.h"
#include "RRPConfigurationDialog.h"
#include <string>
LRESULT RRPConfigurationDialog::OnCbnSelchangeNewsCombo(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
int currentSelection = newsCombo.GetCurSel();
if(addNewsButtonIndex != currentSelection) {
char *aText = comboEntries[currentSelection];
NewsButtonInfo *newsButton = NULL;
UINT n = configManager->getSize();
for(UINT i = 0;i<n;i++) {
newsButton = configManager->getItem(i);
if(newsButton)
if(strcmp(newsButton->title,aText) == 0)
break;
}
if(newsButton) {
SetDlgItemText(IDC_TITLE,newsButton->title);
SetDlgItemText(IDC_LINK,newsButton->link);
return 0;
}
}
SetDlgItemText(IDC_TITLE,"Enter title!");
SetDlgItemText(IDC_LINK,"Enter link!");
CEdit edit = GetDlgItem(IDC_TITLE);
edit.SetFocus();
return 0;
}
LRESULT RRPConfigurationDialog::OnEnSetfocusTitle(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
return 0;
}
LRESULT RRPConfigurationDialog::OnRemove(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) {
unsigned int currentSelection = newsCombo.GetCurSel();
if(currentSelection == addNewsButtonIndex)
return 0;
char *aText = comboEntries[currentSelection];
NewsButtonInfo *newsButton = NULL;
UINT n = configManager->getSize();
UINT i = 0;
for(i = 0;i<n;i++) {
newsButton = configManager->getItem(i);
if(newsButton)
if(strcmp(newsButton->title,aText) == 0)
break;
}
if(newsButton) {
//i specifies the index of the button,to be deleted
configManager->getToolbar()->removeButton(i);
newsCombo.ResetContent();
fillComboBox();
newsCombo.AddString("Add news button!!");
newsCombo.SetCurSel(0);
BOOL handled = true;
OnCbnSelchangeNewsCombo(0,0,0,handled);
}
return 0;
}
LRESULT RRPConfigurationDialog::OnSave(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) {
char *title = new char[100];
char *link = new char[100];
int tFlag = 0,lFlag = 0;
GetDlgItemText(IDC_TITLE,title,100);
GetDlgItemText(IDC_LINK,link,100);
int currentSelection = newsCombo.GetCurSel();
NewsButtonInfo *newsButton = configManager->getItem(currentSelection);
int validFlag = 0;
if(strcmp(title,"Enter title!") == 0)
tFlag = 1;
if(strcmp(link,"Enter link!") == 0)
lFlag = 1;
if(strcmp(title,"") == 0)
tFlag = 1;
if(strcmp(link,"") == 0)
lFlag = 1;
if(checkHyperLink(link) == 0)
validFlag = 1;
if(tFlag && lFlag)
MessageBox("Enter title and link of RSS for the new Button!","Error",MB_ICONERROR);
else if(tFlag)
MessageBox("Enter title for the new Button!","Error",MB_ICONERROR);
else if(lFlag && !validFlag)
MessageBox("Enter link of RSS for the new Button!","Error",MB_ICONERROR);
if(validFlag)
MessageBox("Enter valid link of RSS for the new Button!","Error",MB_ICONERROR);
if(currentSelection == addNewsButtonIndex) {
/*
int validFlag = 0;
if(strcmp(title,"Enter title!") == 0)
tFlag = 1;
if(strcmp(link,"Enter link!") == 0)
lFlag = 1;
if(strcmp(title,"") == 0)
tFlag = 1;
if(strcmp(link,"") == 0)
lFlag = 1;
if(checkHyperLink(link) == 0)
validFlag = 1;
if(tFlag && lFlag)
MessageBox("Enter title and link of RSS for the new Button!","Error",MB_ICONERROR);
else if(tFlag)
MessageBox("Enter title for the new Button!","Error",MB_ICONERROR);
else if(lFlag && !validFlag)
MessageBox("Enter link of RSS for the new Button!","Error",MB_ICONERROR);
if(validFlag)
MessageBox("Enter valid link of RSS for the new Button!","Error",MB_ICONERROR);*/
if(tFlag == 0 && lFlag == 0 && validFlag == 0)
configManager->addNews(title,link);
}
else {
configManager->modifyNews(currentSelection,title,link);
}
//Reset everything
newsCombo.ResetContent();
fillComboBox();
newsCombo.AddString("Add news button!!");
newsCombo.SetCurSel(0);
BOOL handled = true;
OnCbnSelchangeNewsCombo(0,0,0,handled);
delete title,link;
return 0;
}
//False if link is invalid
BOOL RRPConfigurationDialog::checkHyperLink(char *link) {
if(strstr(link,"http://") == link)
return 1;
return 0;
}