Main Page | Class List | File List | Class Members | File Members | Related Pages

ftpcontrol.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Bojan D.                                        *
00003  *   bojan_d@users.sourceforge.net                                         *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00028 #include <kio/job.h>
00029 #include <klocale.h>
00030 
00031 #include "configuration.h" 
00032 #include "ftpcontrol.h"
00033 
00034 FtpControl::FtpControl(QObject *parent, const char *name)
00035  : QObject(parent, name)
00036 {
00037         m_thumbJob = 0;
00038         m_mainJob = 0;
00039 }
00040 
00041 
00042 FtpControl::~FtpControl()
00043 {
00044         delete (KIO::FileCopyJob* ) m_thumbJob;
00045         m_thumbJob = 0;
00046         
00047         delete (KIO::FileCopyJob* ) m_mainJob;
00048         m_thumbJob = 0;
00049 }
00050 
00051 void FtpControl::jobFinished(KIO::Job* job)
00052 {
00053         
00054         if(job->error()) emit error(job->errorString());
00055         
00056         if(job == m_mainJob)
00057         {
00058                 emit message(i18n("Main transfer finished."));
00059                 emit message(i18n("Main transfer finished."), Configuration::Normal);
00060                                 
00061                 if(Config().Ftp.UseThumb) sendThumb(m_thumbSrc, m_thumbDest);
00062                 else emit finishTransfer();
00063         }
00064         
00065         if(job == m_thumbJob)
00066         {
00067                 emit message(i18n("Thumbnail transfer finished."));
00068                 emit message(i18n("Thumbnail transfer finished."), Configuration::Normal);
00069                 emit finishTransfer();
00070         }
00071 }
00072 
00073 void FtpControl::stop()
00074 {
00075         if(m_mainJob) m_mainJob->kill();
00076         if(m_thumbJob) m_thumbJob->kill();
00077 }
00078 
00079 void FtpControl::sendFiles()
00080 {
00081         setupMain();
00082         if(Config().Ftp.UseThumb) setupThumb();
00083         // and send it
00084         emit startTransfer();
00085         sendMain(m_mainSrc, m_mainDest);
00086 }
00087 
00088 void FtpControl::sendThumb(const KURL & src, const KURL & dest, int permissions)
00089 {
00090         
00091         m_thumbJob = KIO::file_copy(src, dest, permissions, true, false, false);
00092         connect(m_thumbJob, SIGNAL(result(KIO::Job *)) , this, SLOT(jobFinished(KIO::Job *)));
00093         
00094         QString log =   i18n("Transfering thumbnail image... ") +
00095                                         i18n("[ ") + dest.prettyURL() + i18n(" ]");
00096 
00097         emit message(i18n("Transfering thumbnail image... "));
00098         emit message(log, Configuration::Normal);
00099 }
00100 
00101 void FtpControl::sendMain(const KURL & src, const KURL & dest, int permissions)
00102 {
00103         m_mainJob = KIO::file_copy(src, dest, permissions, true, false, false);
00104         connect(m_mainJob, SIGNAL(result(KIO::Job *)) , this, SLOT(jobFinished(KIO::Job *)));
00105 
00106         QString log =   i18n("Transfering main image... ") +
00107                                         i18n("[ ") + dest.prettyURL() + i18n(" ]");
00108         
00109         emit message(i18n("Transfering main image... "));
00110         emit message(log, Configuration::Normal);
00111 }
00112 
00113 void FtpControl::setupMain()
00114 {
00115         m_mainDest.setProtocol("ftp");
00116         m_mainDest.setUser(Config().Ftp.User);
00117         m_mainDest.setPass(Config().Ftp.Password);
00118         m_mainDest.setHost(Config().Ftp.Host);
00119         m_mainDest.setPort(Config().Ftp.Port);
00120         m_mainDest.setPath("/" + Config().Ftp.TransferPath + "/" + (KURL(Config().File.PathMain)).fileName());
00121         
00122         m_mainSrc = KURL(Config().File.PathMain);
00123 }
00124         
00125 void FtpControl::setupThumb()
00126 {
00127         m_thumbDest.setProtocol("ftp");
00128         m_thumbDest.setUser(Config().Ftp.User);
00129         m_thumbDest.setPass(Config().Ftp.Password);
00130         m_thumbDest.setHost(Config().Ftp.Host);
00131         m_thumbDest.setPort(Config().Ftp.Port);
00132         m_thumbDest.setPath(Config().Ftp.TransferPath + "/" + (KURL(Config().File.PathThumb)).fileName());
00133         
00134         m_thumbSrc = KURL("/" + Config().File.PathThumb);
00135 }
00136         
00137 void FtpControl::setupOffline()
00138 {
00139         // set up main destination URL
00140         m_mainDest.setProtocol("ftp");
00141         m_mainDest.setUser(Config().Ftp.User);
00142         m_mainDest.setPass(Config().Ftp.Password);
00143         m_mainDest.setHost(Config().Ftp.Host);
00144         m_mainDest.setPort(Config().Ftp.Port);
00145         m_mainDest.setPath("/" + Config().Ftp.TransferPath + "/" + (KURL(Config().File.PathMain)).fileName());
00146         
00147         m_mainSrc = KURL(Config().File.PathOffline);
00148         
00149         //set up thumb destination URL
00150         m_thumbDest.setProtocol("ftp");
00151         m_thumbDest.setUser(Config().Ftp.User);
00152         m_thumbDest.setPass(Config().Ftp.Password);
00153         m_thumbDest.setHost(Config().Ftp.Host);
00154         m_thumbDest.setPort(Config().Ftp.Port);
00155         m_thumbDest.setPath("/" + Config().Ftp.TransferPath + "/" + (KURL(Config().File.PathThumb)).fileName());
00156         
00157         m_thumbSrc = KURL(Config().File.PathOffline);
00158 }
00159 
00160 void FtpControl::sendOffline()
00161 {
00162         setupOffline();
00163         emit startTransfer();
00164         sendMain(m_mainSrc, m_mainDest);
00165 }
00166         
00167 
00168 #include "ftpcontrol.moc"

Generated on Mon Sep 5 12:52:33 2005 for kwebsnap.kdevelop by  doxygen 1.3.9.1