/*
* Copyright (C) 2003 Twink, spm7@waikato.ac.nz
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "stdafx.h"
#include "../client/DCPlusPlus.h"
#include "Resource.h"
#include "../client/SettingsManager.h"
#include "../Client/FavoriteManager.h"
#include "PreviewPage.h"
#include "PreviewDlg.h"
#include "WinUtil.h"
PropPage::TextItem PreviewPage::texts[] = {
{ IDC_ADD_MENU, ResourceManager::ADD },
{ IDC_CHANGE_MENU, ResourceManager::SETTINGS_CHANGE },
{ IDC_REMOVE_MENU, ResourceManager::REMOVE },
{ IDC_WINAMP_BROWSE, ResourceManager::BROWSE },
{ IDC_McDC_WINAMP, ResourceManager::SETMcDC_WINAMP },
{ IDC_McDC_OTHER_PLAYERS, ResourceManager::SETMcDC_PLAYERS },
{ IDC_WINAMP_FOLDER, ResourceManager::OPEN_DOT },
{ 0, ResourceManager::SETTINGS_AUTO_AWAY }
};
PropPage::Item PreviewPage::items[] = {
{ IDC_WINAMP, SettingsManager::WINAMP_FORMAT, PropPage::T_STR },
{ IDC_WINAMP_LOCATION, SettingsManager::WINAMP_LOCATION, PropPage::T_STR },
{ IDC_ITUNES_FORMAT, SettingsManager::ITUNES_FORMAT, PropPage::T_STR },
{ IDC_MPLAYERC_FORMAT, SettingsManager::MPLAYERC_FORMAT, PropPage::T_STR },
{ IDC_FOOBAR_FORMAT, SettingsManager::FOOBAR_FORMAT, PropPage::T_STR },
{ 0, 0, PropPage::T_END }
};
LRESULT PreviewPage::onInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/){
PropPage::translate((HWND)(*this), texts);
PropPage::read((HWND)*this, items);
CRect rc;
ctrlCommands.Attach(GetDlgItem(IDC_MENU_ITEMS));
ctrlCommands.GetClientRect(rc);
ctrlCommands.InsertColumn(0, CTSTRING(SETTINGS_NAME), LVCFMT_LEFT, rc.Width()/5, 0);
ctrlCommands.InsertColumn(1, CTSTRING(APPLICATION), LVCFMT_LEFT, rc.Width()*2 / 5, 1);
ctrlCommands.InsertColumn(2, CTSTRING(SETTINGS_ARGUMENT), LVCFMT_LEFT, rc.Width() / 5, 2);
ctrlCommands.InsertColumn(3, CTSTRING(SETTINGS_EXTENSIONS), LVCFMT_LEFT, rc.Width() / 5, 3);
DWORD styles = LVS_EX_LABELTIP;
if (BOOLSETTING(FULL_ROW_SELECT))
styles |= LVS_EX_FULLROWSELECT;
if (BOOLSETTING(SHOW_INFOTIPS))
styles |= LVS_EX_INFOTIP;
if (BOOLSETTING(HIGHLIGHT_MOUSEOVER))
styles |= LVS_EX_UNDERLINEHOT | LVS_EX_ONECLICKACTIVATE;
if(!(WinUtil::getOsMajor() >= 5 && WinUtil::getOsMinor() >= 1 //WinXP & WinSvr2003
|| WinUtil::getOsMajor() >= 6 )) //Vista
{
styles |= 0x00010000;
}
ctrlCommands.SetExtendedListViewStyle(styles);
// Do specialized reading here
PreviewApplication::List lst = FavoriteManager::getInstance()->getPreviewApps();
for(PreviewApplication::Iter i = lst.begin(); i != lst.end(); ++i) {
PreviewApplication::Ptr pa = *i;
addEntry(pa, ctrlCommands.GetItemCount());
}
return 0;
}
void PreviewPage::write(){
PropPage::write((HWND)*this, items);
}
void PreviewPage::addEntry(PreviewApplication::Ptr pa, int pos) {
TStringList lst;
lst.push_back(Text::toT(pa->getName()));
lst.push_back(Text::toT(pa->getApplication()));
lst.push_back(Text::toT(pa->getArguments()));
lst.push_back(Text::toT(pa->getExtension()));
ctrlCommands.insert(pos, lst, 0, 0);
}
LRESULT PreviewPage::onAddMenu(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/){
PreviewDlg dlg;
if(dlg.DoModal() == IDOK){
addEntry(FavoriteManager::getInstance()->addPreviewApp(Text::fromT(dlg.name), Text::fromT(dlg.application), Text::fromT(dlg.argument), Text::fromT(dlg.extensions)), ctrlCommands.GetItemCount());
}
return 0;
}
LRESULT PreviewPage::onChangeMenu(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/){
if(ctrlCommands.GetSelectedCount() == 1) {
int sel = ctrlCommands.GetSelectedIndex();
PreviewApplication pa;
FavoriteManager::getInstance()->getPreviewApp(sel, pa);
PreviewDlg dlg;
dlg.name = Text::toT(pa.getName());
dlg.application = Text::toT(pa.getApplication());
dlg.argument = Text::toT(pa.getArguments());
dlg.extensions = Text::toT(pa.getExtension());
if(dlg.DoModal() == IDOK) {
pa.setName(Text::fromT(dlg.name));
pa.setApplication(Text::fromT(dlg.application));
pa.setArguments(Text::fromT(dlg.argument));
pa.setExtension(Text::fromT(dlg.extensions));
FavoriteManager::getInstance()->updatePreviewApp(sel, pa);
ctrlCommands.SetItemText(sel, 0, dlg.name.c_str());
ctrlCommands.SetItemText(sel, 1, dlg.application.c_str());
ctrlCommands.SetItemText(sel, 2, dlg.argument.c_str());
ctrlCommands.SetItemText(sel, 3, dlg.extensions.c_str());
}
}
return 0;
}
LRESULT PreviewPage::onRemoveMenu(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/){
Remove();
return 0;
}
LRESULT PreviewPage::onBrowseWinamp(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
TCHAR buf[MAX_PATH];
GetDlgItemText(IDC_WINAMP_LOCATION, buf, MAX_PATH);
tstring x = buf;
if(WinUtil::browseDirectory(x, m_hWnd) == IDOK) {
SetDlgItemText(IDC_WINAMP_LOCATION, x.c_str());
}
return 0;
}
LRESULT PreviewPage::onClickedWinampHelp(WORD /* wNotifyCode */, WORD /*wID*/, HWND /* hWndCtl */, BOOL& /* bHandled */) {
MessageBox(CTSTRING(WINAMP_HELP), CTSTRING(WINAMP_HELP_DESC), MB_OK | MB_ICONINFORMATION);
return S_OK;
}
LRESULT PreviewPage::onKeyDown(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/) {
NMLVKEYDOWN* kd = (NMLVKEYDOWN*) pnmh;
if(kd->wVKey == VK_DELETE) {
Remove();
}
return 0;
}
void PreviewPage::Remove() {
if(ctrlCommands.GetSelectedCount() == 1) {
int sel = ctrlCommands.GetSelectedIndex();
FavoriteManager::getInstance()->removePreviewApp(sel);
ctrlCommands.DeleteItem(sel);
}
}
/**
* @file
* $Id: PreviewPage.cpp 104 2006-10-22 22:09:40Z crakter $
*/