|
From: <arn...@us...> - 2008-03-30 08:15:32
|
Revision: 1088
http://dcplusplus.svn.sourceforge.net/dcplusplus/?rev=1088&view=rev
Author: arnetheduck
Date: 2008-03-30 01:15:26 -0700 (Sun, 30 Mar 2008)
Log Message:
-----------
Use sw load/save dialogs
Modified Paths:
--------------
dcplusplus/trunk/changelog.txt
dcplusplus/trunk/smartwin/include/smartwin/WidgetFactory.h
dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectFileFilter.h
dcplusplus/trunk/win32/Appearance2Page.cpp
dcplusplus/trunk/win32/CertificatesPage.cpp
dcplusplus/trunk/win32/DirectoryListingFrame.cpp
dcplusplus/trunk/win32/MainWindow.cpp
dcplusplus/trunk/win32/QueueFrame.cpp
dcplusplus/trunk/win32/SearchFrame.cpp
dcplusplus/trunk/win32/WinUtil.cpp
dcplusplus/trunk/win32/WinUtil.h
Added Paths:
-----------
dcplusplus/trunk/smartwin/source/widgets/LoadDialog.cpp
dcplusplus/trunk/smartwin/source/widgets/SaveDialog.cpp
Property Changed:
----------------
dcplusplus/trunk/
Property changes on: dcplusplus/trunk
___________________________________________________________________
Name: bzr:revision-info
- timestamp: 2008-03-29 09:16:19.821000099 +0100
committer: Jacek Sieka <arn...@gm...>
properties:
branch-nick: dcplusplus
+ timestamp: 2008-03-29 11:32:16.434999943 +0100
committer: Jacek Sieka <arn...@gm...>
properties:
branch-nick: dcplusplus
Name: bzr:file-ids
-
+ smartwin/source/widgets/LoadDialog.cpp loaddialog.cpp-20080329103151-2zvxbm5b87on29pc-1
smartwin/source/widgets/SaveDialog.cpp savedialog.cpp-20080329103151-2zvxbm5b87on29pc-2
Name: bzr:revision-id:v3-trunk1
- 1027 arn...@gm...-20080323183926-schknwnkgeo7ivdn
1028 zouzou123gen-20080323220411-r8usuc3qxwuh7zsn
1029 zouzou123gen-20080323221249-0su72zaj13e706mk
1030 arn...@gm...-20080324140623-muba1dl46m000o8c
1031 zouzou123gen-20080324141933-qbgr93ugpe0297m6
1032 arn...@gm...-20080324153706-siidja05n84i00b1
1033 arn...@gm...-20080324153823-lhn3awurnu77riln
1034 arn...@gm...-20080324165650-zapppziji67yf5a2
1035 zouzou123gen-20080324175936-4mqc2kh0lo5wtdu2
1036 zouzou123gen-20080325004602-6wdsoym95mjuhwd3
1037 arn...@gm...-20080325100659-8fqy6q65itmghlep
1038 zouzou123gen-20080325175216-s297sdiucukfvijh
1039 arn...@gm...-20080325210137-3dfqyoi8ykosy087
1040 arn...@gm...-20080325211747-nwwy1eb33r071sca
1041 arn...@gm...-20080326084110-qbselrjckku275xi
1042 zouzou123gen-20080326123631-35642mgbk2i4ty32
1043 zouzou123gen-20080326124345-f4xwn2d3ty8ubd6r
1044 arn...@gm...-20080326162031-il0nyms30w0mky43
1045 arn...@gm...-20080326164801-8dru8mjc06xgzjpv
1046 arn...@gm...-20080326170438-uzl2rx8fqnohak7g
1047 zouzou123gen-20080326172821-d6uqcbmfb0c6rwlv
1048 arn...@gm...-20080326213257-qlgdh7m2712p2l0q
1049 arn...@gm...-20080326214313-ktnoekgk3s0wmatz
1050 arn...@gm...-20080326215256-0j1iqrf286b9g7zf
1051 arn...@gm...-20080327082121-hoi22wh1gwjdfbyd
1052 arn...@gm...-20080327120639-um3tukdt374rwvgm
1053 zouzou123gen-20080327130703-6vtek6uxy3vua543
1054 arn...@gm...-20080327215831-dmg5mkufskabwkro
1055 arn...@gm...-20080327231459-cdztcv25alsuyqmf
1056 arn...@gm...-20080328085925-gceybsr53oml1p24
1057 arn...@gm...-20080328200512-1sjuu6bcnl2dyd2a
1058 arn...@gm...-20080328210347-bussqjrm5mfswh7o
1059 arn...@gm...-20080329055630-braiir1dskv7a4qm
1060 arn...@gm...-20080329061558-rck8dz60wpj3c5ja
1061 arn...@gm...-20080329081253-if6o5jn329mbzfpl
1062 arn...@gm...-20080329081619-cb4x930j8sp55cs0
+ 1027 arn...@gm...-20080323183926-schknwnkgeo7ivdn
1028 zouzou123gen-20080323220411-r8usuc3qxwuh7zsn
1029 zouzou123gen-20080323221249-0su72zaj13e706mk
1030 arn...@gm...-20080324140623-muba1dl46m000o8c
1031 zouzou123gen-20080324141933-qbgr93ugpe0297m6
1032 arn...@gm...-20080324153706-siidja05n84i00b1
1033 arn...@gm...-20080324153823-lhn3awurnu77riln
1034 arn...@gm...-20080324165650-zapppziji67yf5a2
1035 zouzou123gen-20080324175936-4mqc2kh0lo5wtdu2
1036 zouzou123gen-20080325004602-6wdsoym95mjuhwd3
1037 arn...@gm...-20080325100659-8fqy6q65itmghlep
1038 zouzou123gen-20080325175216-s297sdiucukfvijh
1039 arn...@gm...-20080325210137-3dfqyoi8ykosy087
1040 arn...@gm...-20080325211747-nwwy1eb33r071sca
1041 arn...@gm...-20080326084110-qbselrjckku275xi
1042 zouzou123gen-20080326123631-35642mgbk2i4ty32
1043 zouzou123gen-20080326124345-f4xwn2d3ty8ubd6r
1044 arn...@gm...-20080326162031-il0nyms30w0mky43
1045 arn...@gm...-20080326164801-8dru8mjc06xgzjpv
1046 arn...@gm...-20080326170438-uzl2rx8fqnohak7g
1047 zouzou123gen-20080326172821-d6uqcbmfb0c6rwlv
1048 arn...@gm...-20080326213257-qlgdh7m2712p2l0q
1049 arn...@gm...-20080326214313-ktnoekgk3s0wmatz
1050 arn...@gm...-20080326215256-0j1iqrf286b9g7zf
1051 arn...@gm...-20080327082121-hoi22wh1gwjdfbyd
1052 arn...@gm...-20080327120639-um3tukdt374rwvgm
1053 zouzou123gen-20080327130703-6vtek6uxy3vua543
1054 arn...@gm...-20080327215831-dmg5mkufskabwkro
1055 arn...@gm...-20080327231459-cdztcv25alsuyqmf
1056 arn...@gm...-20080328085925-gceybsr53oml1p24
1057 arn...@gm...-20080328200512-1sjuu6bcnl2dyd2a
1058 arn...@gm...-20080328210347-bussqjrm5mfswh7o
1059 arn...@gm...-20080329055630-braiir1dskv7a4qm
1060 arn...@gm...-20080329061558-rck8dz60wpj3c5ja
1061 arn...@gm...-20080329081253-if6o5jn329mbzfpl
1062 arn...@gm...-20080329081619-cb4x930j8sp55cs0
1063 arn...@gm...-20080329103216-hgjzo7ra2zixbztd
Modified: dcplusplus/trunk/changelog.txt
===================================================================
--- dcplusplus/trunk/changelog.txt 2008-03-30 08:14:41 UTC (rev 1087)
+++ dcplusplus/trunk/changelog.txt 2008-03-30 08:15:26 UTC (rev 1088)
@@ -12,6 +12,7 @@
* Fixed selection glitches
* Both up&downloads are disconnected if evil users quit (thanks poy)
* Add average share to status bar (thanks mikejj)
+* Minor improvements to load / save dialogs
-- 0.705 2008-03-14 --
* Several patches for better *nix compatibility of the core (thanks steven sheehy et al)
Modified: dcplusplus/trunk/smartwin/include/smartwin/WidgetFactory.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/WidgetFactory.h 2008-03-30 08:14:41 UTC (rev 1087)
+++ dcplusplus/trunk/smartwin/include/smartwin/WidgetFactory.h 2008-03-30 08:15:26 UTC (rev 1088)
@@ -254,7 +254,7 @@
/// Creates a LoadFileDialog and returns a pointer to it.
/** Use this one to construct a ( stack object ) to show a Load File Dialog
*/
- LoadDialog createLoadFile();
+ LoadDialog createLoadDialog();
/// Creates a SaveFileDialog and returns a pointer to it.
/** Use this one to construct a ( stack object ) to show a Save File Dialog
@@ -486,7 +486,7 @@
template<typename ContainerWidgetType>
typename WidgetFactory< ContainerWidgetType >::LoadDialog
-WidgetFactory< ContainerWidgetType >::createLoadFile()
+WidgetFactory< ContainerWidgetType >::createLoadDialog()
{
return LoadDialog ( this );
}
Modified: dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectFileFilter.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectFileFilter.h 2008-03-30 08:14:41 UTC (rev 1087)
+++ dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectFileFilter.h 2008-03-30 08:15:26 UTC (rev 1088)
@@ -78,6 +78,7 @@
WidgetType& setDefaultExtension(const SmartUtil::tstring& defExt) {
itsDefExt = defExt;
+ return *static_cast<WidgetType*>(this);
}
/// Returns the active filter of the object
Added: dcplusplus/trunk/smartwin/source/widgets/LoadDialog.cpp
===================================================================
--- dcplusplus/trunk/smartwin/source/widgets/LoadDialog.cpp (rev 0)
+++ dcplusplus/trunk/smartwin/source/widgets/LoadDialog.cpp 2008-03-30 08:15:26 UTC (rev 1088)
@@ -0,0 +1,51 @@
+#include "../../include/smartwin/widgets/LoadDialog.h"
+
+namespace SmartWin {
+
+bool LoadDialog::open(SmartUtil::tstring& file)
+{
+ OPENFILENAME ofn = { sizeof(OPENFILENAME) }; // common dialog box structure
+ fillOFN( ofn, OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY );
+
+ if ( ::GetOpenFileName( & ofn ) ) {
+ file = ofn.lpstrFile;
+ return true;
+ }
+ return false;
+}
+
+bool LoadDialog::open(std::vector<SmartUtil::tstring>& files)
+{
+ OPENFILENAME ofn = { sizeof(OPENFILENAME) }; // common dialog box structure
+ fillOFN( ofn, OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT );
+ if( ::GetOpenFileName(&ofn) )
+ {
+ // If a single file is selected, the lpstrFile string is just the path terminated by TWO null bytes
+ // If multiple files are selected, the format of the string returned is:
+ // DIRECTORY_PATH + '\0' + FILE_NAME_1 + '\0' + FILE_NAME_2 + '\0' + ... + FILE_NAME_N + '\0' + '\0'
+ // (Note the last file name is terminated by two null bytes)
+
+ SmartUtil::tstring fileName;
+ SmartUtil::tstring filePath;
+ SmartUtil::tstring directory;
+ directory = ofn.lpstrFile; // tstring ends at first null
+ TCHAR *array_p = ofn.lpstrFile + directory.length() + 1; // set pointer to one position past null
+ fileName = array_p; // fileName is substring from array_p to next null
+ if (fileName.length() == 0) // only one file was selected
+ files.push_back(directory); // string 'directory' contains full path
+ else
+ {
+ while (fileName.length() > 0)
+ {
+ filePath = directory + _T("\\") + fileName;
+ files.push_back(filePath);
+ array_p = array_p + fileName.length() + 1; // set pointer one position past null
+ fileName = array_p; // fileName is substring from array_p to next null
+ }
+ }
+ return true;
+ }
+ return false;
+}
+
+}
Added: dcplusplus/trunk/smartwin/source/widgets/SaveDialog.cpp
===================================================================
--- dcplusplus/trunk/smartwin/source/widgets/SaveDialog.cpp (rev 0)
+++ dcplusplus/trunk/smartwin/source/widgets/SaveDialog.cpp 2008-03-30 08:15:26 UTC (rev 1088)
@@ -0,0 +1,16 @@
+#include "../../include/smartwin/widgets/SaveDialog.h"
+
+namespace SmartWin {
+
+bool SaveDialog::open(SmartUtil::tstring& target) {
+ OPENFILENAME ofn = { sizeof(OPENFILENAME) }; // common dialog box structure
+ fillOFN( ofn, 0 );
+
+ if ( ::GetSaveFileName( & ofn ) ) {
+ target = ofn.lpstrFile;
+ return true;
+ }
+ return false;
+}
+
+}
Modified: dcplusplus/trunk/win32/Appearance2Page.cpp
===================================================================
--- dcplusplus/trunk/win32/Appearance2Page.cpp 2008-03-30 08:14:41 UTC (rev 1087)
+++ dcplusplus/trunk/win32/Appearance2Page.cpp 2008-03-30 08:15:26 UTC (rev 1088)
@@ -157,7 +157,7 @@
::GetDlgItemText(handle(), IDC_BEEPFILE, buf, MAX_PATH);
tstring x = buf;
- if(WinUtil::browseFile(x, handle(), false) == IDOK) {
+ if(createLoadDialog().open(x)) {
setItemText(IDC_BEEPFILE, x);
}
}
Modified: dcplusplus/trunk/win32/CertificatesPage.cpp
===================================================================
--- dcplusplus/trunk/win32/CertificatesPage.cpp 2008-03-30 08:14:41 UTC (rev 1087)
+++ dcplusplus/trunk/win32/CertificatesPage.cpp 2008-03-30 08:15:26 UTC (rev 1088)
@@ -90,13 +90,13 @@
void CertificatesPage::handleBrowsePrivateKeyClicked() {
tstring target = privateKeyFile->getText();
- if(WinUtil::browseFile(target, handle(), false, target))
+ if(createLoadDialog().setInitialDirectory(target).open(target))
privateKeyFile->setText(target);
}
void CertificatesPage::handleBrowseCertificateClicked() {
tstring target = certificateFile->getText();
- if(WinUtil::browseFile(target, handle(), false, target))
+ if(createLoadDialog().setInitialDirectory(target).open(target))
certificateFile->setText(target);
}
Modified: dcplusplus/trunk/win32/DirectoryListingFrame.cpp
===================================================================
--- dcplusplus/trunk/win32/DirectoryListingFrame.cpp 2008-03-30 08:14:41 UTC (rev 1087)
+++ dcplusplus/trunk/win32/DirectoryListingFrame.cpp 2008-03-30 08:15:26 UTC (rev 1088)
@@ -260,7 +260,7 @@
void DirectoryListingFrame::handleListDiff() {
tstring file;
- if(WinUtil::browseFile(file, handle(), false, Text::toT(Util::getListPath()), _T("File Lists\0*.xml.bz2\0All Files\0*.*\0"))) {
+ if(WinUtil::browseFileList(createLoadDialog(), file)) {
DirectoryListing dirList(dl->getUser());
try {
dirList.loadFile(Text::fromT(file));
@@ -493,7 +493,7 @@
try {
if(ii->type == ItemInfo::FILE) {
tstring target = Text::toT(SETTING(DOWNLOAD_DIRECTORY)) + ii->getText(COLUMN_FILENAME);
- if(WinUtil::browseFile(target, handle())) {
+ if(createSaveDialog().open(target)) {
WinUtil::addLastDir(Util::getFilePath(target));
dl->download(ii->file, Text::fromT(target), false, WinUtil::isShift());
}
Modified: dcplusplus/trunk/win32/MainWindow.cpp
===================================================================
--- dcplusplus/trunk/win32/MainWindow.cpp 2008-03-30 08:14:41 UTC (rev 1087)
+++ dcplusplus/trunk/win32/MainWindow.cpp 2008-03-30 08:15:26 UTC (rev 1088)
@@ -696,11 +696,9 @@
UPnP_TCPConnection = UPnP_UDPConnection = NULL;
}
-static const TCHAR types[]= _T("File Lists\0*.DcLst;*.xml.bz2\0All Files\0*.*\0");
-
void MainWindow::handleOpenFileList() {
tstring file;
- if (WinUtil::browseFile(file, handle(), false, Text::toT(Util::getListPath()), types)) {
+ if(WinUtil::browseFileList(createLoadDialog(), file)) {
UserPtr u = DirectoryListing::getUserFromFilename(Text::fromT(file));
if (u) {
DirectoryListingFrame::openWindow(getMDIParent(), file, Text::toT(Util::emptyString), u, 0);
Modified: dcplusplus/trunk/win32/QueueFrame.cpp
===================================================================
--- dcplusplus/trunk/win32/QueueFrame.cpp 2008-03-30 08:14:41 UTC (rev 1087)
+++ dcplusplus/trunk/win32/QueueFrame.cpp 2008-03-30 08:15:26 UTC (rev 1088)
@@ -703,23 +703,8 @@
// Single file, get the full filename and move...
QueueItemInfo* ii = files->getSelectedData();
tstring target = Text::toT(ii->getTarget());
- tstring ext = Util::getFileExt(target);
- tstring ext2;
- if (!ext.empty())
- {
- ext = ext.substr(1); // remove leading dot so default extension works when browsing for file
- ext2 = _T("*.") + ext;
- ext2 += (TCHAR)0;
- ext2 += _T("*.") + ext;
- }
- ext2 += _T("*.*");
- ext2 += (TCHAR)0;
- ext2 += _T("*.*");
- ext2 += (TCHAR)0;
-
- tstring path = Text::toT(ii->getPath());
- if(WinUtil::browseFile(target, handle(), true, path, ext2.c_str(), ext.empty() ? NULL : ext.c_str())) {
+ if(WinUtil::browseSaveFile(createSaveDialog(), target)) {
QueueManager::getInstance()->move(ii->getTarget(), Text::fromT(target));
}
} else if(n > 1) {
Modified: dcplusplus/trunk/win32/SearchFrame.cpp
===================================================================
--- dcplusplus/trunk/win32/SearchFrame.cpp 2008-03-30 08:14:41 UTC (rev 1087)
+++ dcplusplus/trunk/win32/SearchFrame.cpp 2008-03-30 08:15:26 UTC (rev 1088)
@@ -667,7 +667,7 @@
if(sr->getType() == SearchResult::TYPE_FILE) {
tstring target = Text::toT(SETTING(DOWNLOAD_DIRECTORY)) + si->columns[COLUMN_FILENAME];
- if(WinUtil::browseFile(target, handle())) {
+ if(WinUtil::browseSaveFile(createSaveDialog(), target)) {
WinUtil::addLastDir(Util::getFilePath(target));
results->forEachSelectedT(SearchInfo::DownloadTarget(target));
}
Modified: dcplusplus/trunk/win32/WinUtil.cpp
===================================================================
--- dcplusplus/trunk/win32/WinUtil.cpp 2008-03-30 08:14:41 UTC (rev 1087)
+++ dcplusplus/trunk/win32/WinUtil.cpp 2008-03-30 08:15:26 UTC (rev 1088)
@@ -402,31 +402,26 @@
lastDirs.push_back(dir);
}
-bool WinUtil::browseFile(tstring& target, HWND owner /* = NULL */, bool save /* = true */, const tstring& initialDir /* = Util::emptyString */, const TCHAR* types /* = NULL */, const TCHAR* defExt /* = NULL */) {
- TCHAR buf[MAX_PATH];
- OPENFILENAME ofn = { 0 }; // common dialog box structure
- target = Text::toT(Util::validateFileName(Text::fromT(target)));
- _tcscpy(buf, target.c_str());
- // Initialize OPENFILENAME
- ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
- ofn.hwndOwner = owner;
- ofn.lpstrFile = buf;
- ofn.lpstrFilter = types;
- ofn.lpstrDefExt = defExt;
- ofn.nFilterIndex = 1;
-
- if(!initialDir.empty()) {
- ofn.lpstrInitialDir = initialDir.c_str();
+bool WinUtil::browseSaveFile(SmartWin::SaveDialog dlg, tstring& file) {
+ tstring ext = Util::getFileExt(file);
+ tstring path = Util::getFilePath(file);
+
+ if(!ext.empty()) {
+ ext = ext.substr(1); // remove leading dot so default extension works when browsing for file
+ dlg.addFilter(str(TF_("%1% files") % ext), _T("*.") + ext);
+ dlg.setDefaultExtension(ext);
}
- ofn.nMaxFile = sizeof(buf);
- ofn.Flags = (save ? 0: OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST);
+ dlg.addFilter(T_("All files"), _T("*.*"));
+ dlg.setInitialDirectory(path);
+
+ return dlg.open(file);
+}
- // Display the Open dialog box.
- if ( (save ? ::GetSaveFileName(&ofn) : ::GetOpenFileName(&ofn) ) ==TRUE) {
- target = ofn.lpstrFile;
- return true;
- }
- return false;
+bool WinUtil::browseFileList(SmartWin::LoadDialog dialog, tstring& file) {
+ return dialog.addFilter(T_("File Lists"), _T("*.xml.bz2"))
+ .addFilter(T_("All files"), _T("*.*"))
+ .setInitialDirectory(Text::toT(Util::getListPath()))
+ .open(file);
}
int WinUtil::getOsMajor() {
Modified: dcplusplus/trunk/win32/WinUtil.h
===================================================================
--- dcplusplus/trunk/win32/WinUtil.h 2008-03-30 08:14:41 UTC (rev 1087)
+++ dcplusplus/trunk/win32/WinUtil.h 2008-03-30 08:15:26 UTC (rev 1088)
@@ -154,8 +154,9 @@
static void addLastDir(const tstring& dir);
static void openLink(const tstring& url);
- static bool browseFile(tstring& target, HWND owner = NULL, bool save = true, const tstring& initialDir = Util::emptyStringT, const TCHAR* types = NULL, const TCHAR* defExt = NULL);
-
+ static bool browseSaveFile(SmartWin::SaveDialog dialog, tstring& file);
+ static bool browseFileList(SmartWin::LoadDialog dialog, tstring& file);
+
static int getOsMajor();
static int getOsMinor();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|