home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2003 June
/
PCWorld_2003-06_cd.bin
/
KOMUNIK
/
MIRRORIT
/
SRC
/
MIRRORITDOC.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1998-02-27
|
11KB
|
455 lines
// MirrorItDoc.cpp : implementation of the CMirrorItDoc class
//
#include "stdafx.h"
#include "MirrorIt.h"
#include "MirrorItDoc.h"
#include "MirrorItView.h"
#include "Session.h"
#include "SessionPropertiesFileNamePage.h"
#include "SessionPropertiesMirrorPage.h"
#include "SessionPropertiesMainPage.h"
#include "SessionPropertiesFileTypesPage.h"
#include "SessionPropertiesLimitPage.h"
#include "SessionPropertiesProxyPage.h"
#include "SessionPropertiesPasswordPage.h"
#include "SessionPropertiesAdvancedPage.h"
#include "SessionPropertiesSheet.h"
#include "HTTPSocket.h"
#include "DownloadDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMirrorItDoc
IMPLEMENT_DYNCREATE(CMirrorItDoc, CDocument)
BEGIN_MESSAGE_MAP(CMirrorItDoc, CDocument)
//{{AFX_MSG_MAP(CMirrorItDoc)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMirrorItDoc construction/destruction
CMirrorItDoc::CMirrorItDoc()
{
// TODO: add one-time construction code here
m_ClipboardOperation = FALSE;
}
CMirrorItDoc::~CMirrorItDoc()
{
}
BOOL CMirrorItDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMirrorItDoc serialization
void CMirrorItDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
ar << 0x10006L;
int count;
POSITION pos = GetFirstViewPosition();
CListView* pFirstView = (CListView *) GetNextView( pos );
CListCtrl & list = pFirstView -> GetListCtrl();
count = sessions.GetSize();
if (m_ClipboardOperation)
{
ar << list.GetSelectedCount();
}
else
{
ar << count;
}
for (int i = 0; i < count; i++)
{
if (m_ClipboardOperation &&
list.GetItemState(i, LVIS_SELECTED) == 0) continue;
CSession *session = (CSession *) sessions.GetAt(i);
ar << session -> m_SessionName;
ar << session -> m_BaseURL;
ar << session -> m_Comment;
ar << session -> m_Directory;
ar << session -> m_LocalURLs;
ar << session -> m_LongFileName;
ar << session -> m_Mirror;
ar << session -> m_BNumberOfLevels;
ar << session -> m_NumberOfLevels;
ar << session -> m_BNumberOfFiles;
ar << session -> m_NumberOfFiles;
ar << session -> m_BNumberOfKBytes;
ar << session -> m_NumberOfBytes;
ar << session -> m_FullName;
ar << session -> m_MimeTypes.GetCount();
POSITION item = session -> m_MimeTypes.GetHeadPosition();
while (item != NULL)
{
ar << session -> m_MimeTypes.GetNext(item);
}
ar << session -> m_ModifiedSince;
ar << session -> m_TModifiedSince;
ar << session -> m_UserName;
ar << session -> m_Password;
ar << session -> m_BProxy;
ar << session -> m_ProxyServer;
ar << session -> m_ProxyPort;
ar << session -> m_NoProxy;
ar << session -> m_Exclude;
ar << session -> m_Multiple;
ar << session -> m_Permanent;
ar << session -> m_Temporary;
}
}
else
{
// TODO: add loading code here
int count, ver;
ar >> ver;
if (ver == 0x10005L)
{
ar >> count;
for (int i = 0; i < count; i++)
{
CString SessionName;
CString BaseURL;
CString Comment;
CString Directory;
int LongFileName, Mirror;
BOOL LocalURLs, FullName, BNumberOfLevels, BNumberOfFiles, BNumberOfKBytes;
UINT NumberOfLevels, NumberOfFiles, NumberOfBytes;
ar >> SessionName;
ar >> BaseURL;
ar >> Comment;
ar >> Directory;
ar >> LocalURLs;
ar >> LongFileName;
ar >> Mirror;
ar >> BNumberOfLevels;
ar >> NumberOfLevels;
ar >> BNumberOfFiles;
ar >> NumberOfFiles;
ar >> BNumberOfKBytes;
ar >> NumberOfBytes;
ar >> FullName;
int mimetypes;
CStringList templist;
ar >> mimetypes;
for (int j = 0; j < mimetypes; j++)
{
CString temp;
ar >> temp;
templist.AddTail(temp);
}
BOOL IfModifiedSince, BProxy;
CTime TIfModifiedSince;
CString UserName, Password, ProxyServer;
UINT ProxyPort;
ar >> IfModifiedSince;
ar >> TIfModifiedSince;
ar >> UserName;
ar >> Password;
ar >> BProxy;
ar >> ProxyServer;
ar >> ProxyPort;
sessions.Add(new CSession(SessionName, BaseURL, Comment, Directory, Mirror, LongFileName, LocalURLs, BNumberOfFiles, NumberOfFiles, BNumberOfLevels, NumberOfLevels, BNumberOfKBytes, NumberOfBytes, FullName, &templist, IfModifiedSince, &TIfModifiedSince, BProxy, ProxyServer, ProxyPort, UserName, Password));
}
}
else
if (ver == 0x10006L)
{
ar >> count;
for (int i = 0; i < count; i++)
{
CString SessionName;
CString BaseURL;
CString Comment;
CString Directory;
int LongFileName, Mirror;
BOOL LocalURLs, FullName, BNumberOfLevels, BNumberOfFiles, BNumberOfKBytes;
UINT NumberOfLevels, NumberOfFiles, NumberOfBytes;
ar >> SessionName;
ar >> BaseURL;
ar >> Comment;
ar >> Directory;
ar >> LocalURLs;
ar >> LongFileName;
ar >> Mirror;
ar >> BNumberOfLevels;
ar >> NumberOfLevels;
ar >> BNumberOfFiles;
ar >> NumberOfFiles;
ar >> BNumberOfKBytes;
ar >> NumberOfBytes;
ar >> FullName;
int mimetypes;
CStringList templist;
ar >> mimetypes;
for (int j = 0; j < mimetypes; j++)
{
CString temp;
ar >> temp;
templist.AddTail(temp);
}
BOOL IfModifiedSince, BProxy, Multiple, Permanent, Temporary;
CTime TIfModifiedSince;
CString UserName, Password, ProxyServer, NoProxy, Exclude;
UINT ProxyPort;
ar >> IfModifiedSince;
ar >> TIfModifiedSince;
ar >> UserName;
ar >> Password;
ar >> BProxy;
ar >> ProxyServer;
ar >> ProxyPort;
ar >> NoProxy;
ar >> Exclude;
ar >> Multiple;
ar >> Permanent;
ar >> Temporary;
sessions.Add(new CSession(SessionName, BaseURL, Comment, Directory, Mirror, LongFileName, LocalURLs, BNumberOfFiles, NumberOfFiles, BNumberOfLevels, NumberOfLevels, BNumberOfKBytes, NumberOfBytes, FullName, &templist, IfModifiedSince, &TIfModifiedSince, BProxy, ProxyServer, ProxyPort, UserName, Password, NoProxy, Exclude, Multiple, Permanent, Temporary));
}
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CMirrorItDoc diagnostics
#ifdef _DEBUG
void CMirrorItDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CMirrorItDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMirrorItDoc commands
void CMirrorItDoc::AddSession()
{
CSessionPropertiesSheet dlg(TRUE);
CSession *session = new CSession;
// session -> m_BaseURL = "doc-baseurl";
// session -> m_SessionName = "doc-sessionname";
// session -> m_Comment = "doc-comment";
dlg.SetData(*session);
if (dlg.DoModal() == IDOK)
{
dlg.GetData(*session);
sessions.Add(session);
SetModifiedFlag();
UpdateAllViews(NULL, UPDATE_ADD, session);
}
else
delete session;
}
void CMirrorItDoc::RemoveSession(CListCtrl & list)
{
int selcount = list.GetSelectedCount();
if (!m_ClipboardOperation && AfxMessageBox(selcount == 1 ? IDM_SESSIONREMOVE : IDM_SESSIONSREMOVE, MB_YESNO) != IDYES) return;
int count = list.GetItemCount();
CPtrArray *items = new CPtrArray;
items -> SetSize(selcount);
int j = 0;
for (int i = count - 1; i >= 0; i--)
if (list.GetItemState(i, LVIS_SELECTED))
{
items -> SetAt(j++, sessions.GetAt(i));
sessions.RemoveAt(i);
}
SetModifiedFlag();
UpdateAllViews(NULL, UPDATE_REMOVE, items);
}
void CMirrorItDoc::PropertiesSession(CListCtrl & list)
{
int count = list.GetItemCount();
int selected = -1;
for (int i = 0; i < count; i++)
if (list.GetItemState(i, LVIS_SELECTED))
{
selected = i;
break;
}
if (selected < 0) return;
PropertiesSession(selected);
}
void CMirrorItDoc::DeleteContents()
{
if (m_ClipboardOperation)
{
POSITION pos = GetFirstViewPosition();
CListView* pFirstView = (CListView *) GetNextView( pos );
CListCtrl & list = pFirstView -> GetListCtrl();
RemoveSession(list);
return;
}
for (int i = sessions.GetSize() - 1; i >= 0; i--)
{
CSession *session = (CSession *) sessions.GetAt(i);
if (session) delete session;
}
sessions.RemoveAll();
CDocument::DeleteContents();
}
void CMirrorItDoc::PropertiesSession(int selected)
{
if (selected < 0) return;
CSessionPropertiesSheet dlg;
CSession *session = (CSession *)sessions.GetAt(selected);
dlg.SetData(*session);
if (dlg.DoModal() == IDOK)
{
if (dlg.GetData(*session))
{
session -> url.parse(session -> m_BaseURL);
SetModifiedFlag();
UpdateAllViews(NULL, UPDATE_MODIFY, session);
}
}
}
void CMirrorItDoc::AddSession(CString SessionName, CString BaseURL)
{
CSession *session = new CSession(SessionName, BaseURL);
sessions.Add(session);
SetModifiedFlag();
UpdateAllViews(NULL, UPDATE_ADD, session);
}
void CMirrorItDoc::MoveupSession(CListCtrl & list)
{
int count = list.GetItemCount();
int selected = -1;
for (int i = 0; i < count; i++)
if (list.GetItemState(i, LVIS_SELECTED))
{
selected = i;
break;
}
if (selected < 1) return; //not found and topmost item
CDWordArray *items = new CDWordArray;
items -> SetSize(2);
items -> SetAt(0, selected);
items -> SetAt(1, selected - 1);
CSession *session = (CSession *)sessions.GetAt(selected - 1);
sessions.SetAt(selected - 1, sessions.GetAt(selected));
sessions.SetAt(selected, session);
UpdateAllViews(NULL, UPDATE_MOVE, items);
}
void CMirrorItDoc::MovedownSession(CListCtrl & list)
{
int count = list.GetItemCount();
int selected = -1;
for (int i = 0; i < count; i++)
if (list.GetItemState(i, LVIS_SELECTED))
{
selected = i;
break;
}
if (selected < 0 || selected >= count - 1) return;
CDWordArray *items = new CDWordArray;
items -> SetSize(2);
items -> SetAt(0, selected);
items -> SetAt(1, selected + 1);
CSession *session = (CSession *)sessions.GetAt(selected);
sessions.SetAt(selected, sessions.GetAt(selected + 1));
sessions.SetAt(selected + 1, session);
UpdateAllViews(NULL, UPDATE_MOVE, items);
}
void CMirrorItDoc::StartSession()
{
AfxGetMainWnd() -> ShowWindow(SW_HIDE);
CDownLoadDlg dlg;
dlg.LoadSessions(sessions);
AfxGetMainWnd() -> ShowWindow(SW_SHOW);
}