Filter:   InfoImg
download PreviewPage.cpp
Language: C++
License: GPL
Copyright: (C) 2003 Twink, spm7@waikato.ac.nz
LOC: 129
Project Info
mcdcplusplus(mcdc)
Server: BerliOS (SVN)
Type: svn
...(SVN)\m\mcdc\trunk\windows\
   AboutDlg.h
   ADLSearchFrame.cpp
   ADLSearchFrame.h
   ADLSProperties.cpp
   ADLSProperties.h
   Advanced3Page.cpp
   Advanced3Page.h
   AdvancedPage.cpp
   AdvancedPage.h
   AGArrayTemplates.cpp
   AGArrayTemplates.h
   AGEmotionSetup.cpp
   AGEmotionSetup.h
   AppearancePage.cpp
   AppearancePage.h
   atlctrlxp.h
   BarShader.cpp
   BarShader.h
   BrowserFrame.cpp
   BrowserFrame.h
   Bumped.cpp
   Bumped.h
   ChatCtrl.cpp
   ChatCtrl.h
   CommandDlg.cpp
   CommandDlg.h
   DebugFrame.cpp
   DebugFrame.h
   DimEdit.h
   DirectoryListingFrm.cpp
   DirectoryListingFrm.h
   DownloadPage.cpp
   DownloadPage.h
   EmoticonsDlg.cpp
   EmoticonsDlg.h
   ExListViewCtrl.cpp
   ExListViewCtrl.h
   ExtendedTrace.cpp
   ExtendedTrace.h
   FavHubProperties.cpp
   FavHubProperties.h
   FavoriteDirsPage.cpp
   FavoriteDirsPage.h
   FavoritesFrm.cpp
   FavoritesFrm.h
   FilterPage.cpp
   FilterPage.h
   FilterPageDlg.h
   FinishedFrame.cpp
   FinishedFrame.h
   FinishedULFrame.cpp
   FinishedULFrame.h
   FlatTabCtrl.h
   FulComboBox.cpp
   FulComboBox.h
   FulTabsPage.cpp
   FulTabsPage.h
   GeneralPage.cpp
   GeneralPage.h
   HashProgressDlg.h
   HelpSystem.cpp
   HelpSystem.h
   HubFrame.cpp
   HubFrame.h
   IgnoreFrame.cpp
   IgnoreFrame.h
   ImageDataObject.cpp
   ImageDataObject.h
   iTunesCOMInterface.h
   iTunesCOMInterface_i.c
   LineDlg.cpp
   LineDlg.h
   ListViewArrows.h
   LogPage.cpp
   LogPage.h
   MagnetDlg.h
   main.cpp
   MainFrm.cpp
   MainFrm.h
   McAdvancedPage.cpp
   McAdvancedPage.h
   McDCPage.cpp
   McDCPage.h
   memdc.h
   NetworkPage.cpp
   NetworkPage.h
   NotepadFrame.cpp
   NotepadFrame.h
   NotepadFrame2.cpp
   NotepadFrame2.h
   OMenu.cpp
   OMenu.h
   OperaColorsPage.cpp
   OperaColorsPage.h
   picturewindow.h
   PopupDlg.h
   PopupManager.cpp
   PopupManager.h
   Popups.cpp
   Popups.h
   PreviewDlg.cpp
   PreviewDlg.h
   PreviewPage.cpp
   PreviewPage.h
   PrivateFrame.cpp
   PrivateFrame.h
   PropertiesDlg.cpp
   PropertiesDlg.h
   PropPage.cpp
   PropPage.h
   PropPageTextStyles.cpp
   PropPageTextStyles.h
   PublicHubsFrm.cpp
   PublicHubsFrm.h
   PublicHubsListDlg.h
   QueueFrame.cpp
   QueueFrame.h
   QueuePage.cpp
   QueuePage.h
   RecentsFrm.cpp
   RecentsFrm.h
   resource.h
   SearchFrm.cpp
   SearchFrm.h
   SecurityPage.cpp
   SecurityPage.h
   SingleInstance.h
   Sntp.cpp
   Sntp.h
   Sounds.cpp
   Sounds.h
   SpyFrame.cpp
   SpyFrame.h
   StaticFrm.h
   StatsFrame.cpp
   StatsFrame.h
   stdafx.cpp
   stdafx.h
   SystemFrame.cpp
   SystemFrame.h
   TextFrame.cpp
   TextFrame.h
   ThemesPage.cpp
   ThemesPage.h
   things.cpp
   things.h
   ToolbarPage.cpp
   ToolbarPage.h
   TransferView.cpp
   TransferView.h
   TreePropertySheet.cpp
   TreePropertySheet.h
   TypedListViewCtrl.h
   UCHandler.h
   UCPage.cpp
   UCPage.h
   UlcPage.cpp
   UlcPage.h
   UploadPage.cpp
   UploadPage.h
   UploadQueueFrame.cpp
   UploadQueueFrame.h
   UPnP.cpp
   UPnP.h
   UserInfo.cpp
   UserInfo.h
   UsersFrame.cpp
   UsersFrame.h
   Winamp.h
   WinampFrame.cpp
   WinampFrame.h
   WindowsPage.cpp
   WindowsPage.h
   WinUtil.cpp
   WinUtil.h

/* 
* 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 $
 */