⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imageview.cpp

📁 网络图片收集软件
💻 CPP
字号:
// imageView.cpp : implementation of the CImageView class
//

#include "stdafx.h"
#include "image.h"

#include "imageDoc.h"
#include "imageView.h"
#include "Progress.h"
#include "SiteSet.h"
#include "Filter.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CImageView

IMPLEMENT_DYNCREATE(CImageView, CView)

BEGIN_MESSAGE_MAP(CImageView, CView)
	//{{AFX_MSG_MAP(CImageView)
	ON_COMMAND(ID_SETPARA, OnSetpara)
	ON_WM_SIZE()
	ON_COMMAND(ID_SITE_SET, OnSiteSet)
	ON_COMMAND(ID_STARTDOWNLOAD, OnStartdownload)
	ON_COMMAND(ID_PAUSE_SERVICE, OnPauseService)
	ON_COMMAND(ID_MENUITEM32776, OnMenuitem32776)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CImageView construction/destruction

CImageView::CImageView()
{
	// TODO: add construction code here
	m_pProgress=NULL;
}

CImageView::~CImageView()
{
	delete m_pProgress;

}

BOOL CImageView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CImageView drawing

void CImageView::OnDraw(CDC* pDC)
{
	CImageDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CImageView diagnostics

#ifdef _DEBUG
void CImageView::AssertValid() const
{
	CView::AssertValid();
}

void CImageView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CImageDoc* CImageView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CImageDoc)));
	return (CImageDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CImageView message handlers

void CImageView::OnSetpara() 
{
	// TODO: Add your command handler code here
	CString str;
	CImageDoc * pDoc=GetDocument();
	COption option(pDoc->GetOption());

	if(option.DoModal()==IDOK)
	{
		
		SITEINFO temp;
		temp.bdownload=pDoc->GetOption()->bDownload;
		temp.imagetype=(short)pDoc->GetOption()->image_type;
		temp.lastnum=0;
		temp.lasttime=pDoc->GetOption()->date;
		temp.max_height=pDoc->GetOption()->max_length;
		temp.max_level=pDoc->GetOption()->max_level;
		temp.max_width=pDoc->GetOption()->max_width;
		temp.min_height=pDoc->GetOption()->min_length;
		temp.min_width=pDoc->GetOption()->min_width;
		temp.priority=atoi(pDoc->GetOption()->priority);
		temp.sitename=pDoc->GetOption()->sitename;
		temp.status=true;
		temp.url=pDoc->GetOption()->url;
		temp.m_exclusive_level=pDoc->GetOption()->exclusive_level;

		pDoc->m_siteinfo.Add(temp);
		int i;
		i=pDoc->m_siteinfo.GetSize();
		FillRow(i-1);

		str.Format(_T("insert into log values('%s','%s',%s,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)"),temp.sitename,temp.url,
			temp.lasttime.Format(_T("%Y-%m-%d")),temp.lastnum,1,temp.priority,temp.imagetype,temp.min_height,temp.max_height,
			temp.min_width,	temp.max_width,temp.bdownload,temp.max_level,temp.m_exclusive_level);		
		CImageApp * app=(CImageApp*)AfxGetApp();

		app->m_db.ExecuteSQL(str);
	

	}
		//pDoc->SetModifiedFlag(TRUE);

	
}

void CImageView::OnInitialUpdate() 
{
	static bool bFirstTime=true;

	CView::OnInitialUpdate();
	
	// TODO: Add your specialized code here and/or call the base class
	//是否是第一次启动
	if(bFirstTime)
	{

		//生成进度条子窗口
		CRect rcProg;
		CRect rc;
		GetClientRect(&rc);

		bFirstTime=false;
		m_pProgress=new CProgress(this);
		m_pProgress->GetClientRect(rcProg);
		m_pProgress->MoveWindow(rc.left,rc.bottom-rcProg.Height(),
			rc.Width(),rcProg.Height());
		m_pProgress->ShowWindow(SW_SHOWNORMAL);
		m_pProgress->UpdateWindow();
		rc.bottom=rc.bottom-rcProg.Height();
		m_siteList.Create(LVS_REPORT|WS_VISIBLE,rc,this,IDC_LIST);
		AddColumns();

	}
	CImageDoc *pDoc=GetDocument();
	pDoc->m_log->Open();
	FillData();
	m_siteList.SetDoc(pDoc);

	
}


void CImageView::OnSize(UINT nType, int cx, int cy) 
{
	CView::OnSize(nType, cx, cy);
	
	// TODO: Add your message handler code here
	CRect rcProg;//,rc;

	if(m_pProgress)
	{
		m_pProgress->GetWindowRect(rcProg);
		m_pProgress->MoveWindow(0,cy-rcProg.Height(),cx,rcProg.Height());
		m_siteList.MoveWindow(0,0,cx,cy-rcProg.Height());

	}
	//AddColumns();
}

void CImageView::OnSiteSet() 
{
	// TODO: Add your command handler code here
	CImageDoc * pDoc=GetDocument();
	CSiteSet dlg;
	dlg.m_strDirectory=pDoc->localset.strDirectory;
	dlg.m_image_size=pDoc->localset.image_min_size;
	dlg.m_max_thread=pDoc->localset.max_thread;
	dlg.m_unlikelevel=pDoc->localset.unlike_level;
	if(dlg.DoModal()!=IDOK)
	{
		AfxMessageBox("本次下载的参数没有设置");		
		return;
	}
	pDoc->localset.bProxy=dlg.m_bProxy;
	pDoc->localset.max_thread=dlg.m_max_thread;
	pDoc->localset.strDirectory=dlg.m_strDirectory;
	pDoc->localset.strProxy=dlg.m_strProxy;
	pDoc->localset.image_min_size=dlg.m_image_size;
	pDoc->localset.unlike_level=dlg.m_unlikelevel;


}

void CImageView::OnStartdownload() 
{
	// TODO: Add your command handler code here
	CString temp;
	CStringArray list;
	int dwRet;

	
	CImageDoc *pDoc=GetDocument();
	pDoc->m_save->Open();

	dwRet=IDNO;
	if(!pDoc->m_save->IsBOF()||!pDoc->m_save->IsEOF())
	dwRet=AfxMessageBox("是否断点续传",MB_YESNO);

	if(dwRet==IDYES)	
	{
		//在这里进行断点续传处理	
		pDoc->m_save->MoveFirst();
		while(!pDoc->m_save->IsEOF())
		{
			list.Add(pDoc->m_save->m_sitename);
			pDoc->m_save->MoveNext();
		}

		bool find;
		for(int i=0;i<pDoc->m_siteinfo.GetSize();i++)
		{
			find=false;
			for(int k=0;k<list.GetSize();k++)
			{
				if(pDoc->m_siteinfo[i].sitename==list[k])
					find=true;
			}
			if(find==true)
				pDoc->m_siteinfo[i].bdownload=true;
			else
				pDoc->m_siteinfo[i].bdownload=false;

		}
		m_siteList.DeleteAllItems();
		FillData();
		
	}
	else
	{
		//现在进行正常的处理
		temp.Format(_T("%s"),"delete from doneurl");
		theApp.m_db.ExecuteSQL(temp);

		temp.Format(_T("%s"),"delete from todownloadurl");
		theApp.m_db.ExecuteSQL(temp);
	}
	pDoc->m_save->Close();
	//现在需要清空表save...
	temp.Format(_T("%s"),"delete from [save]");
	theApp.m_db.ExecuteSQL(temp);

	//对于特别情况进行特别的处理
	this->m_pProgress->SetAborted(false);

	pDoc->BeginToDownLoad();
	
}

void CImageView::OnPauseService() 
{
	// TODO: Add your command handler code here
	this->m_pProgress->SetAborted(true);
}



void CImageView::FillData()
{
	CImageDoc *pDoc=GetDocument();
	m_siteList.DeleteAllItems();
	for(int i=0;i<pDoc->m_siteinfo.GetSize();i++)
	{
		FillRow(i);				
	}

}

void CImageView::AddColumns()
{
	UINT i;
	CImageApp *app=(CImageApp *)AfxGetApp();
	
	//0 item
	i=app->GetProfileInt(_T("APPEARANCE"),_T("ITEM0"),60);
	m_siteList.InsertColumn(0,"是否下载",LVCFMT_CENTER,i);

	//1 item
	i=app->GetProfileInt("APPEARANCE","ITEM1",140);
	m_siteList.InsertColumn(1,"网站名",LVCFMT_LEFT,i);

	//2 item
	i=app->GetProfileInt("APPEARANCE","ITEM2",180);
	m_siteList.InsertColumn(2,"网站对应的超链",LVCFMT_LEFT,i);

	//3 item
	i=app->GetProfileInt("APPEARANCE","ITEM3",80);
	m_siteList.InsertColumn(3,"操作时间",LVCFMT_LEFT,i);

	//4 item
	i=app->GetProfileInt("APPEARANCE","ITEM4",50);
	m_siteList.InsertColumn(4,"下载量",LVCFMT_LEFT,i);

	//5 item
	i=app->GetProfileInt("APPEARANCE","ITEM5",40);
	m_siteList.InsertColumn(5,"状态",LVCFMT_LEFT,i);

	//6 item
	i=app->GetProfileInt("APPEARANCE","ITEM6",50);
	m_siteList.InsertColumn(6,"星级",LVCFMT_LEFT,i);

	//7 item
	i=app->GetProfileInt("APPEARANCE","ITEM7",50);
	m_siteList.InsertColumn(7,"图类型",LVCFMT_LEFT,0);

	//8 item
	i=app->GetProfileInt("APPEARANCE","ITEM8",40);
	m_siteList.InsertColumn(8,"最小高",LVCFMT_LEFT,i);

	//9 item
	i=app->GetProfileInt("APPEARANCE","ITEM9",40);
	m_siteList.InsertColumn(9,"最大高",LVCFMT_LEFT,i);

	//10 item
	i=app->GetProfileInt("APPEARANCE","ITEM10",40);
	m_siteList.InsertColumn(10,"最小宽",LVCFMT_LEFT,i);

	//11 item
	i=app->GetProfileInt("APPEARANCE","ITEM11",40);
	m_siteList.InsertColumn(11,"最大宽",LVCFMT_LEFT,i);

	//12 item
	i=app->GetProfileInt("APPEARANCE","ITEM12",40);
	m_siteList.InsertColumn(12,"层数",LVCFMT_LEFT,i);

	//13 item
	i=app->GetProfileInt("APPEARANCE","ITEM13",60);
	m_siteList.InsertColumn(13,"图片层数",LVCFMT_LEFT,i);

}

void CImageView::FillRow(int i)
{
	SITEINFO siteinfo;
	CImageDoc *pDoc=GetDocument();

		CString temp;
		siteinfo=pDoc->m_siteinfo[i];
		if(siteinfo.bdownload)
			m_siteList.InsertItem(i,"是");
		else
			m_siteList.InsertItem(i,"否");
		
		m_siteList.SetItem(i,1,LVIF_TEXT,siteinfo.sitename,-1,0,0,0);
		m_siteList.SetItem(i,2,LVIF_TEXT,siteinfo.url,-1,0,0,0);
		m_siteList.SetItem(i,3,LVIF_TEXT,siteinfo.lasttime.Format("%d-%m-%Y"),-1,0,0,0);
		
		temp.Format(_T("%d"),siteinfo.lastnum);
		m_siteList.SetItem(i,4,LVIF_TEXT,temp,-1,0,0,0);
		
		if(siteinfo.status)
			m_siteList.SetItem(i,5,LVIF_TEXT,"OK",-1,0,0,0);
		else
			m_siteList.SetItem(i,5,LVIF_TEXT,"NO",-1,0,0,0);
		
		switch(siteinfo.priority)
		{
		case 1:
			temp="*";
			break;
		case 2:
			temp="**";
			break;
		case 3:
			temp="***";
			break;
		case 4:
			temp="****";
			break;
		case 5:
			temp="*****";
			break;
		default:
			temp="error";
		}
		m_siteList.SetItem(i,6,LVIF_TEXT,temp,-1,0,0,0);
		
		temp.Format(_T("%d"),siteinfo.imagetype);
		m_siteList.SetItem(i,7,LVIF_TEXT,temp,-1,0,0,0);

		temp.Format(_T("%d"),siteinfo.min_height);
		m_siteList.SetItem(i,8,LVIF_TEXT,temp,-1,0,0,0);

		temp.Format(_T("%d"),siteinfo.max_height);
		m_siteList.SetItem(i,9,LVIF_TEXT,temp,-1,0,0,0);

		temp.Format(_T("%d"),siteinfo.min_width);
		m_siteList.SetItem(i,10,LVIF_TEXT,temp,-1,0,0,0);

		temp.Format(_T("%d"),siteinfo.max_width);
		m_siteList.SetItem(i,11,LVIF_TEXT,temp,-1,0,0,0);
		
		temp.Format(_T("%d"),siteinfo.max_level);
		m_siteList.SetItem(i,12,LVIF_TEXT,temp,-1,0,0,0);

		temp.Format(_T("%d"),siteinfo.m_exclusive_level);
		m_siteList.SetItem(i,13,LVIF_TEXT,temp,-1,0,0,0);

}

void CImageView::SaveAppearance()
{
	int i;
	LVCOLUMN col;
	CString item;
	
	//保存列表框的外观
	CImageApp *app=(CImageApp*)AfxGetApp();
	col.mask=LVCF_WIDTH;

	for(int k=0;k<14;k++)
	{
		m_siteList.GetColumn(k,&col);
		i=col.cx;
		item.Format(_T("ITEM%d"),k);
		app->WriteProfileInt("APPEARANCE",item,i);
	}

}

void CImageView::OnMenuitem32776() 
{
	// TODO: Add your command handler code here
	CImageDoc * pDoc=(CImageDoc *)GetDocument();
	CFilter filter(pDoc,this);
	
	filter.DoModal();

	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -