browsercore/appfw/Api/Managers/downloadcontroller.cpp
changeset 12 afcd8e6d025b
parent 3 0954f5dd2cd0
equal deleted inserted replaced
11:786160610b4d 12:afcd8e6d025b
    31 #include <QString>
    31 #include <QString>
    32 #include <QUrl>
    32 #include <QUrl>
    33 #include <QWebPage>
    33 #include <QWebPage>
    34 
    34 
    35 #ifdef USE_DOWNLOAD_MANAGER
    35 #ifdef USE_DOWNLOAD_MANAGER
    36 #include "download.h"
    36 using namespace WRT;
    37 #include "downloadmanager.h"
    37 
    38 
    38 static const char * downloadErrorToString(WRT::Error error)
    39 static const char * downloadErrorToString(QNetworkReply::NetworkError error)
       
    40 {
    39 {
    41     switch (error) {
    40     switch (error) {
    42     case QNetworkReply::NoError:
    41     case WRT::NoError:
    43         return "QNetworkReply::NoError";
    42         return "WRT::NoError";
    44     case QNetworkReply::ConnectionRefusedError:
    43     case WRT::ConnectionRefusedError:
    45         return "QNetworkReply::ConnectionRefusedError";
    44         return "WRT::ConnectionRefusedError";
    46     case QNetworkReply::RemoteHostClosedError:
    45     case WRT::RemoteHostClosedError:
    47         return "QNetworkReply::RemoteHostClosedError";
    46         return "WRT::RemoteHostClosedError";
    48     case QNetworkReply::HostNotFoundError:
    47     case WRT::HostNotFoundError:
    49         return "QNetworkReply::HostNotFoundError";
    48         return "WRT::HostNotFoundError";
    50     case QNetworkReply::TimeoutError:
    49     case WRT::TimeoutError:
    51         return "QNetworkReply::TimeoutError";
    50         return "WRT::TimeoutError";
    52     case QNetworkReply::OperationCanceledError:
    51     case WRT::OperationCanceledError:
    53         return "QNetworkReply::OperationCanceledError";
    52         return "WRT::OperationCanceledError";
    54     case QNetworkReply::SslHandshakeFailedError:
    53     case WRT::SslHandshakeFailedError:
    55         return "QNetworkReply::SslHandshakeFailedError";
    54         return "WRT::SslHandshakeFailedError";
    56     case QNetworkReply::ProxyConnectionRefusedError:
    55     case WRT::TemporaryNetworkFailureError:
    57         return "QNetworkReply::ProxyConnectionRefusedError";
    56         return "WRT::TemporaryNetworkFailureError";
    58     case QNetworkReply::ProxyConnectionClosedError:
    57     case WRT::UnknownNetworkError:
    59         return "QNetworkReply::ProxyConnectionClosedError";
    58         return "WRT::UnknownNetworkError";
    60     case QNetworkReply::ProxyNotFoundError:
    59     case WRT::ProxyConnectionRefusedError:
    61         return "QNetworkReply::ProxyNotFoundError";
    60         return "WRT::ProxyConnectionRefusedError";
    62     case QNetworkReply::ProxyTimeoutError:
    61     case WRT::ProxyConnectionClosedError:
    63         return "QNetworkReply::ProxyTimeoutError";
    62         return "WRT::ProxyConnectionClosedError";
    64     case QNetworkReply::ProxyAuthenticationRequiredError:
    63     case WRT::ProxyNotFoundError:
    65         return "QNetworkReply::ProxyAuthenticationRequiredError";
    64         return "WRT::ProxyNotFoundError";
    66     case QNetworkReply::ContentAccessDenied:
    65     case WRT::ProxyTimeoutError:
    67         return "QNetworkReply::ContentAccessDenied";
    66         return "WRT::ProxyTimeoutError";
    68     case QNetworkReply::ContentOperationNotPermittedError:
    67     case WRT::ProxyAuthenticationRequiredError:
    69         return "QNetworkReply::ContentOperationNotPermittedError";
    68         return "WRT::ProxyAuthenticationRequiredError";
    70     case QNetworkReply::ContentNotFoundError:
    69     case WRT::UnknownProxyError:
    71         return "QNetworkReply::ContentNotFoundError";
    70         return "WRT::UnknownProxyError";
    72     case QNetworkReply::AuthenticationRequiredError:
    71     case WRT::ContentAccessDenied:
    73         return "QNetworkReply::AuthenticationRequiredError";
    72         return "WRT::ContentAccessDenied";
    74     case QNetworkReply::ContentReSendError:
    73     case WRT::ContentOperationNotPermittedError:
    75         return "QNetworkReply::ContentReSendError";
    74         return "WRT::ContentOperationNotPermittedError";
    76     case QNetworkReply::ProtocolUnknownError:
    75     case WRT::ContentNotFoundError:
    77         return "QNetworkReply::ProtocolUnknownError";
    76         return "WRT::ContentNotFoundError";
    78     case QNetworkReply::ProtocolInvalidOperationError:
    77     case WRT::AuthenticationRequiredError:
    79         return "QNetworkReply::ProtocolInvalidOperationError";
    78         return "WRT::AuthenticationRequiredError";
    80     case QNetworkReply::UnknownNetworkError:
    79     case WRT::ContentReSendError:
    81         return "QNetworkReply::UnknownNetworkError";
    80         return "WRT::ContentReSendError";
    82     case QNetworkReply::UnknownProxyError:
    81     case WRT::UnknownContentError:
    83         return "QNetworkReply::UnknownProxyError";
    82         return "WRT::UnknownContentError";
    84     case QNetworkReply::UnknownContentError:
    83     case WRT::ProtocolUnknownError:
    85         return "QNetworkReply::UnknownContentError";
    84         return "WRT::ProtocolUnknownError";
    86     case QNetworkReply::ProtocolFailure:
    85     case WRT::ProtocolInvalidOperationError:
    87         return "QNetworkReply::ProtocolFailure";
    86         return "WRT::ProtocolInvalidOperationError";
       
    87     case WRT::ProtocolFailure:
       
    88         return "WRT::ProtocolFailure";
       
    89     case WRT::ConnectionFailed:
       
    90         return "WRT::ConnectionFailed";
       
    91     case WRT::HttpRestartFailed:
       
    92         return "WRT::HttpRestartFailed";
       
    93     case WRT::ContentExpired:
       
    94         return "WRT::ContentExpired";
       
    95     case WRT::PartialContentModified:
       
    96         return "WRT::PartialContentModified";
       
    97     case WRT::ObjectNotFound:
       
    98         return "WRT::ObjectNotFound";
       
    99     case WRT::HttpUnhandled:
       
   100         return "WRT::HttpUnhandled";
       
   101     case WRT::DestinationFileInUse:
       
   102         return "WRT::DestinationFileInUse";
       
   103     case WRT::WrongDestinationFilename:
       
   104         return "WRT::WrongDestinationFilename";
       
   105     case WRT::BadUrl:
       
   106         return "WRT::BadUrl";
       
   107     case WRT::MediaRemoved:
       
   108         return "WRT::MediaRemoved";
       
   109     case WRT::FileWriteFailed:
       
   110         return "WRT::FileWriteFailed";
       
   111     case WRT::FileNotFound:
       
   112         return "WRT::FileNotFound";
       
   113     case WRT::InvalidDrive:
       
   114         return "WRT::InvalidDrive";
       
   115     case WRT::MoveFailed:
       
   116         return "WRT::MoveFailed";
       
   117     case WRT::DiskFull:
       
   118         return "WRT::DiskFull";
       
   119     case WRT::DiskError:
       
   120         return "WRT::DiskError";
       
   121     case WRT::TransactionFailed:
       
   122         return "WRT::TransactionFailed";
       
   123     case WRT::Internal:
       
   124         return "WRT::Internal";
       
   125     case WRT::General:
       
   126         return "WRT::General";
       
   127     case WRT::MaxRedirectionsReached:
       
   128         return "WRT::MaxRedirectionsReached";
       
   129     case WRT::InvalidDownloadDescriptor:
       
   130         return "WRT::InvalidDownloadDescriptor";
    88     default:
   131     default:
    89         return "???";
   132         return "???";
    90     }
   133     }
    91 }
   134 }
    92 
   135 
    93 static const char * downloadEventToString(DEventType type)
   136 static const char * downloadEventToString(WRT::DownloadEvent::Event type)
    94 {
   137 {
    95     switch (type) {
   138     switch (type) {
    96     case DownloadCreated:
   139     case WRT::DownloadEvent::Created:
    97         return "DownloadManager:DownloadCreated";
   140         return "DownloadEvent:Created";
    98     case DownloadsCleared:
   141     case WRT::DownloadEvent::Started:
    99         return "DownloadManager:DownloadsCleared";
   142         return "DownloadEvent::Started";
   100     case ConnectedToServer:
   143     case WRT::DownloadEvent::HeadersReceived:
   101         return "DownloadManager:ConnectedToServer";
   144         return "DownloadEvent::HeadersReceived";
   102     case DisconnectedFromServer:
   145     case WRT::DownloadEvent::InProgress:
   103         return "DownloadManager:DisconnectedFromServer";
   146         return "DownloadEvent::InProgress";
   104     case ServerError:
   147     case WRT::DownloadEvent::Paused:
   105         return "DownloadManager:ServerError";
   148         return "DownloadEvent::Paused";
   106     case Started:
   149     case WRT::DownloadEvent::Completed:
   107         return "Download:Started";
   150         return "DownloadEvent::Completed";
   108     case HeaderReceived:
   151     case WRT::DownloadEvent::Failed:
   109         return "Download:HeaderReceived";
   152         return "DownloadEvent::Failed";
   110     case Progress:
   153     case WRT::DownloadEvent::Cancelled:
   111         return "Download:Progress";
   154         return "DownloadEvent::Cancelled";
   112     case Completed:
   155     case WRT::DownloadEvent::DescriptorUpdated:
   113         return "Download:Completed";
   156         return "DownloadEvent::DescriptorUpdated";
   114     case Paused:
   157     case WRT::DownloadEvent::NetworkLoss:
   115         return "Download:Paused";
   158         return "DownloadEvent::NetworkLoss";
   116     case Cancelled:
   159     case WRT::DownloadEvent::Error:
   117         return "Download:Cancelled";
   160         return "DownloadEvent::Error";
   118     case Failed:
   161     case WRT::DownloadEvent::DescriptorReady:
   119         return "Download:Failed";
   162         return "DownloadEvent::DescriptorReady";
   120     case DescriptorUpdated:
   163     case WRT::DownloadEvent::LicenseAcquiring:
   121         return "Download:DescriptorUpdated";
   164         return "DownloadEvent::LicenseAcquiring";
   122     case NetworkLoss:
   165     case WRT::DownloadEvent::MediaRemoved:
   123         return "Download:NetworkLoss";
   166         return "DownloadEvent::MediaRemoved";
   124     case Error:
   167     case WRT::DownloadEvent::MediaInserted:
   125         return "Download:Error";
   168         return "DownloadEvent::MediaInserted";
   126     case OMADownloadDescriptorReady:
   169     case WRT::DownloadEvent::RedirectedPermanently:
   127         return "Download:OMADownloadDescriptorReady";
   170         return "DownloadEvent::RedirectedPermanently";
   128     case WMDRMLicenseAcquiring:
   171     case WRT::DownloadEvent::RedirectedTemporarily:
   129         return "Download:WMDRMLicenseAcquiring";
   172         return "DownloadEvent::RedirectedTemporarily";
       
   173     case WRT::DownloadEvent::NameChanged:
       
   174         return "DownloadEvent::NameChanged";
       
   175     case WRT::DownloadEvent::ContentTypeChanged:
       
   176         return "DownloadEvent::ContentTypeChanged";
       
   177     case WRT::DownloadEvent::CreatingConnection:
       
   178         return "DownloadEvent::CreatingConnection";
       
   179     case WRT::DownloadEvent::ConnectionNeeded:
       
   180         return "DownloadEvent::ConnectionNeeded";
       
   181     case WRT::DownloadEvent::ConnectionDisconnected:
       
   182         return "DownloadEvent::ConnectionDisconnected";
       
   183     case WRT::DownloadEvent::RightObjectsAcquired:
       
   184         return "DownloadEvent::RightObjectsAcquired";
   130     default:
   185     default:
   131         return 0;
   186         return 0;
   132     }
   187     }
   133 }
   188 }
   134 
   189 
   135 static void debugDownloadEvent(DEventType type)
   190 static void debugDownloadEvent(WRT::DownloadEvent::Event type)
   136 {
   191 {
   137     const char * name = downloadEventToString(type);
   192     const char * name = downloadEventToString(type);
   138     if (name == 0) {
   193     if (name == 0) {
   139         return;
   194         return;
   140     }
   195     }
   149     const QString & client,
   204     const QString & client,
   150     const QNetworkProxy & proxy)
   205     const QNetworkProxy & proxy)
   151 {
   206 {
   152     m_downloadController = downloadController;
   207     m_downloadController = downloadController;
   153 
   208 
   154     m_downloadManager = new DownloadManager(client);
   209     m_downloadManager = new WRT::DownloadManager(client);
   155     m_downloadManager->registerEventReceiver(this);
   210 
       
   211     if (m_downloadManager->initialize() != 0) {
       
   212         return;
       
   213     }
       
   214 
       
   215     if (!connect(
       
   216                 m_downloadManager,
       
   217                 SIGNAL(downloadManagerEvent(DownloadManagerEvent *)),
       
   218                 this,
       
   219                 SLOT(handleDownloadManagerEvent(DownloadManagerEvent *)))) {
       
   220         //;;; how to handle error?
       
   221     }
       
   222 
   156     if (proxy.type() != QNetworkProxy::NoProxy)
   223     if (proxy.type() != QNetworkProxy::NoProxy)
   157         m_downloadManager->setProxy(proxy.hostName(), proxy.port());
   224         m_downloadManager->setProxy(proxy.hostName(), proxy.port());
   158 }
   225 }
   159 
   226 
   160 DownloadControllerPrivate::~DownloadControllerPrivate()
   227 DownloadControllerPrivate::~DownloadControllerPrivate()
   194     return QString();
   261     return QString();
   195 }
   262 }
   196 
   263 
   197 void DownloadControllerPrivate::startDownload(const QUrl & url, const QFileInfo & info)
   264 void DownloadControllerPrivate::startDownload(const QUrl & url, const QFileInfo & info)
   198 {
   265 {
   199     Download * download = m_downloadManager->createDownload(url.toString());
   266     WRT::Download * download = m_downloadManager->createDownload(url.toString());
   200 
   267 
   201     download->setAttribute(DlDestPath, info.absolutePath());
   268     download->setAttribute(WRT::DestinationPath, info.absolutePath());
   202     download->setAttribute(DlFileName, info.fileName());
   269     download->setAttribute(WRT::FileName, info.fileName());
   203 
   270 
   204     startDownload(download, url);
   271     startDownload(download, url);
   205 }
   272 }
   206 
   273 
   207 void DownloadControllerPrivate::startDownload(QNetworkReply * reply)
   274 void DownloadControllerPrivate::startDownload(QNetworkReply * reply)
   208 {
   275 {
   209     QUrl url = reply->url();
   276     QUrl url = reply->url();
   210 
   277 
   211     Download * download = m_downloadManager->createDownload(reply);
   278     WRT::Download * download = m_downloadManager->createDownload(reply);
   212 
   279 
   213     startDownload(download, url);
   280     startDownload(download, url);
   214 }
   281 }
   215 
   282 
   216 void DownloadControllerPrivate::startDownload(const QNetworkRequest & request)
   283 void DownloadControllerPrivate::startDownload(const QNetworkRequest & request)
   217 {
   284 {
   218     QUrl url = request.url();
   285     QUrl url = request.url();
   219 
   286 
   220     Download * download = m_downloadManager->createDownload(url.toString());
   287     WRT::Download * download = m_downloadManager->createDownload(url.toString());
   221 
   288 
   222     startDownload(download, url);
   289     startDownload(download, url);
   223 }
   290 }
   224 
   291 
   225 void DownloadControllerPrivate::startDownload(Download * download, const QUrl & url)
   292 void DownloadControllerPrivate::startDownload(WRT::Download * download, const QUrl & url)
   226 {
   293 {
   227     // If necessary suggest an alternate file name.
   294     // If necessary suggest an alternate file name.
   228     // The download manager will adjust the file name for us to handle
   295     // The download manager will adjust the file name for us to handle
   229     // duplicates in the destination directory.
   296     // duplicates in the destination directory.
   230 
   297 
   231     QString file = downloadFileName(url);
   298     QString file = downloadFileName(url);
   232 
   299 
   233     if (file.length() > 0) {
   300     if (file.length() > 0) {
   234         QVariant value(file);
   301         QVariant value(file);
   235         download->setAttribute(DlFileName, value);
   302         download->setAttribute(WRT::FileName, value);
   236     }
   303     }
   237 
   304 
   238     // Start download.
   305     // Start download.
   239 
   306 
   240     DownloadProxy downloadProxy(new DownloadProxyData(download));
   307     DownloadProxy downloadProxy(new DownloadProxyData(download));
   241 
   308 
   242     emit m_downloadController->downloadCreated(downloadProxy);
   309     emit m_downloadController->downloadCreated(downloadProxy);
   243 
   310 
   244     download->registerEventReceiver(this);
   311     if (!connect(
       
   312                 download,
       
   313                 SIGNAL(downloadEvent(DownloadEvent *)),
       
   314                 this,
       
   315                 SLOT(handleDownloadEvent(DownloadEvent *)))) {
       
   316         //;;; how to handle error?
       
   317     }
       
   318 
       
   319     if (!connect(
       
   320                 download,
       
   321                 SIGNAL(downloadError(Error)),
       
   322                 this,
       
   323                 SLOT(handleDownloadError(Error)))) {
       
   324         //;;; how to handle error?
       
   325     }
   245 
   326 
   246     download->start();
   327     download->start();
   247 }
   328 
   248 
   329 }
   249 bool DownloadControllerPrivate::handleDownloadManagerEvent(DownloadEvent * event)
   330 
   250 {
   331 void DownloadControllerPrivate::handleDownloadManagerEvent(
   251     DEventType type = static_cast<DEventType>(event->type());
   332         DownloadManagerEvent * event)
       
   333 {
       
   334     int type = event->type();
   252 
   335 
   253     switch (type) {
   336     switch (type) {
   254     case DownloadCreated:
   337     case WRT::DownloadManagerEvent::Created:
   255         // Instead of waiting for the DownloadManager DownloadCreated event
   338         // Instead of waiting for the DownloadManager Created event
   256         // we emit downloadCreated in startDownload above so that we can add
   339         // we emit downloadCreated in startDownload above so that we
   257         // a pointer to the download created as a parameter.
   340         // can add a pointer to the download created as a parameter.
   258         return true;
   341         return;
   259 
   342 
   260     case DownloadsCleared:
   343     case WRT::DownloadManagerEvent::Removed:
   261         // ;;; In new DL mgr will have DownloadManager 'Removed' event instead.
   344         if (m_downloadManager->currentDownloads().empty()) {
   262         // ;;; Looks like this will only be generated when all downloads are removed.
   345             emit m_downloadController->downloadsCleared();
   263         // ;;; In that case we can emit the same signal.
   346         }
   264         emit m_downloadController->downloadsCleared();
   347         return;
   265         return true;
       
   266 
       
   267     case ConnectedToServer:
       
   268     case DisconnectedFromServer:
       
   269     case ServerError:
       
   270         return true;
       
   271 
   348 
   272     default:
   349     default:
   273         qDebug() << "Unexpected download manager event:" << type;
   350         qDebug() << "Unexpected download manager event:" << type;
   274         return false;
   351         return;
   275     }
   352     }
   276 }
   353 }
   277 
   354 
   278 bool DownloadControllerPrivate::handleDownloadEvent(DownloadEvent * event)
   355 void DownloadControllerPrivate::handleDownloadEvent(
   279 {
   356         DownloadEvent * event)
   280     DEventType type = static_cast<DEventType>(event->type());
   357 {
   281 
   358     int id = event->id();
   282     DownloadEvent * dlEvent = static_cast<DownloadEvent*>(event);
   359 
   283 
   360     WRT::Download * download = m_downloadManager->findDownload(id);
   284     int dlId = dlEvent->getId();
       
   285 
       
   286     Download * download = m_downloadManager->findDownload(dlId);
       
   287 
   361 
   288     if (!download) {
   362     if (!download) {
   289         qDebug() << "Cannot found download with id" << dlId;
   363         qDebug() << "Cannot find download with id" << id << " for error " << event;
   290         return false;
   364         return;
   291     }
   365     }
   292 
   366 
   293     int errorNum = download->getAttribute(DlLastError).toInt();
   367     int errorNum = download->attribute(WRT::LastError).toInt();
   294 
   368 
   295     const char * errorStr = downloadErrorToString(
   369     const char * errorStr = downloadErrorToString(
   296             static_cast<QNetworkReply::NetworkError>(errorNum));
   370             static_cast<WRT::Error>(errorNum));
   297 
   371 
   298     QString error;
   372     QString error;
   299     if (errorStr != 0)
   373     if (errorStr != 0)
   300         error = errorStr;
   374         error = errorStr;
   301 
   375 
   302     DownloadProxy downloadProxy(new DownloadProxyData(download));
   376     DownloadProxy downloadProxy(new DownloadProxyData(download));
   303 
   377 
   304     switch (type)
   378     switch (event->type())
   305     {
   379     {
   306     case Started:
   380 
       
   381     case WRT::DownloadEvent::Created:
       
   382         // Nothing to do, we already emitted a signal to report
       
   383         // creation of a new Download object from startDownload().
       
   384         return;
       
   385 
       
   386     case WRT::DownloadEvent::Started:
   307         emit m_downloadController->downloadStarted(downloadProxy);
   387         emit m_downloadController->downloadStarted(downloadProxy);
   308         return true;
   388         return;
   309 
   389 
   310     case HeaderReceived:
   390     case WRT::DownloadEvent::HeadersReceived:
   311         emit m_downloadController->downloadHeaderReceived(downloadProxy);
   391         emit m_downloadController->downloadHeaderReceived(downloadProxy);
   312         return true;
   392         return;
   313 
   393 
   314     case Progress:
   394     case WRT::DownloadEvent::InProgress:
   315         emit m_downloadController->downloadProgress(downloadProxy);
   395         emit m_downloadController->downloadProgress(downloadProxy);
   316         return true;
   396         return;
   317 
   397 
   318     case Completed:
   398     case WRT::DownloadEvent::Completed:
   319         emit m_downloadController->downloadFinished(downloadProxy);
   399         emit m_downloadController->downloadFinished(downloadProxy);
   320         return true;
   400         return;
   321 
   401 
   322     case Paused:
   402     case WRT::DownloadEvent::Paused:
   323         emit m_downloadController->downloadPaused(downloadProxy, error);
   403         emit m_downloadController->downloadPaused(downloadProxy, error);
   324         return true;
   404         return;
   325 
   405 
   326     case Cancelled:
   406     case WRT::DownloadEvent::Cancelled:
   327         emit m_downloadController->downloadCancelled(downloadProxy, error);
   407         emit m_downloadController->downloadCancelled(downloadProxy, error);
   328         return true;
   408         return;
   329 
   409 
   330     case Failed:
   410     case WRT::DownloadEvent::Failed:
   331         emit m_downloadController->downloadFailed(downloadProxy, error);
   411         emit m_downloadController->downloadFailed(downloadProxy, error);
   332         return true;
   412         return;
   333 
   413 
   334     case DescriptorUpdated:
   414     case WRT::DownloadEvent::DescriptorUpdated:
   335         // FIXME ;;; Update to support OMA and DRM.
   415         // FIXME - Update to support OMA and DRM.
   336         return true;
   416         return;
   337 
   417 
   338     case NetworkLoss:
   418     case WRT::DownloadEvent::NetworkLoss:
   339         emit m_downloadController->downloadNetworkLoss(downloadProxy, error);
   419         emit m_downloadController->downloadNetworkLoss(downloadProxy, error);
   340         return true;
   420         return;
   341 
   421 
   342     case Error:
   422     case WRT::DownloadEvent::Error:
   343         emit m_downloadController->downloadError(downloadProxy, error);
   423         emit m_downloadController->downloadError(downloadProxy, error);
   344         return true;
   424         return;
   345 
   425 
   346     case OMADownloadDescriptorReady:
   426     case WRT::DownloadEvent::DescriptorReady:
   347         // FIXME ;;; Update to support OMA and DRM.
   427         // FIXME - Update to support OMA and DRM.
   348         return true;
   428         return;
   349 
   429 
   350     case WMDRMLicenseAcquiring:
   430     case WRT::DownloadEvent::LicenseAcquiring:
   351         // FIXME ;;; Update to support OMA and DRM.
   431         // FIXME - Update to support OMA and DRM.
   352         return true;
   432         return;
       
   433 
       
   434     case WRT::DownloadEvent::MediaRemoved:
       
   435         // FIXME ;;; what to do?
       
   436         emit m_downloadController->downloadMessage(
       
   437                 downloadProxy,
       
   438                 "Media Removed");
       
   439         return;
       
   440 
       
   441     case WRT::DownloadEvent::MediaInserted:
       
   442         // FIXME ;;; what to do?
       
   443         emit m_downloadController->downloadMessage(
       
   444                 downloadProxy,
       
   445                 "Media Inserted");
       
   446         return;
       
   447 
       
   448     case WRT::DownloadEvent::RedirectedPermanently:
       
   449         // FIXME ;;; what to do?
       
   450         emit m_downloadController->downloadMessage(
       
   451                 downloadProxy,
       
   452                 "Redirected Permanently");
       
   453         return;
       
   454 
       
   455     case WRT::DownloadEvent::RedirectedTemporarily:
       
   456         // FIXME ;;; what to do?
       
   457         emit m_downloadController->downloadMessage(
       
   458                 downloadProxy,
       
   459                 "Redirected Temporarily");
       
   460         return;
       
   461 
       
   462     case WRT::DownloadEvent::NameChanged:
       
   463         // FIXME ;;; what to do?
       
   464         emit m_downloadController->downloadMessage(
       
   465                 downloadProxy,
       
   466                 "Name Changed");
       
   467         return;
       
   468 
       
   469     case WRT::DownloadEvent::ContentTypeChanged:
       
   470         // FIXME ;;; what to do?
       
   471         emit m_downloadController->downloadMessage(
       
   472                 downloadProxy,
       
   473                 "Type Changed");
       
   474         return;
       
   475 
       
   476     case WRT::DownloadEvent::CreatingConnection:
       
   477         // FIXME ;;; what to do?
       
   478         emit m_downloadController->downloadMessage(
       
   479                 downloadProxy,
       
   480                 "Creating Connection");
       
   481         return;
       
   482 
       
   483     case WRT::DownloadEvent::ConnectionNeeded:
       
   484         // FIXME ;;; what to do?
       
   485         emit m_downloadController->downloadMessage(
       
   486                 downloadProxy,
       
   487                 "Connection Needed");
       
   488         return;
       
   489 
       
   490     case WRT::DownloadEvent::ConnectionDisconnected:
       
   491         // FIXME ;;; what to do?
       
   492         emit m_downloadController->downloadMessage(
       
   493                 downloadProxy,
       
   494                 "Connection Disconnected");
       
   495         return;
       
   496 
       
   497     case WRT::DownloadEvent::RightObjectsAcquired:
       
   498         // FIXME - Update to support OMA and DRM.
       
   499         return;
   353 
   500 
   354     default:
   501     default:
   355         qDebug() << "Unexpected download event:" << type;
   502         qDebug() << "Unexpected download event:" << event->type();
   356         break;
   503         break;
   357     }
   504     }
   358 
   505 }
   359     return false;
   506 
   360 }
   507 void DownloadControllerPrivate::handleDownloadError(Error error)
   361 
   508 {
   362 bool DownloadControllerPrivate::event(QEvent * e)
   509     // Expect the WRT::DownloadEvent::Error case in handleDownloadEvent()
   363 {
   510     // above should handle anything likely to go through here.
   364     DownloadEvent * event = static_cast<DownloadEvent *>(e);
       
   365 
       
   366     DEventType type = static_cast<DEventType>(event->type());
       
   367 
       
   368     debugDownloadEvent(type);
       
   369 
       
   370     switch (type) {
       
   371     case DownloadCreated:
       
   372     case DownloadsCleared:
       
   373     case ConnectedToServer:
       
   374     case DisconnectedFromServer:
       
   375     case ServerError:
       
   376         return handleDownloadManagerEvent(event);
       
   377 
       
   378     case Started:
       
   379     case HeaderReceived:
       
   380     case Progress:
       
   381     case Completed:
       
   382     case Paused:
       
   383     case Cancelled:
       
   384     case Failed:
       
   385     case DescriptorUpdated:
       
   386     case NetworkLoss:
       
   387     case Error:
       
   388     case OMADownloadDescriptorReady:
       
   389     case WMDRMLicenseAcquiring:
       
   390         return handleDownloadEvent(event);
       
   391 
       
   392     default:
       
   393         return false;
       
   394     }
       
   395 }
   511 }
   396 
   512 
   397 // DownloadController implementation
   513 // DownloadController implementation
   398 
   514 
   399 DownloadController::DownloadController(
   515 DownloadController::DownloadController(
   436 #else // USE_DOWNLOAD_MANAGER
   552 #else // USE_DOWNLOAD_MANAGER
   437 
   553 
   438 // Empty implementation for when DownloadManager is unsupported.
   554 // Empty implementation for when DownloadManager is unsupported.
   439 
   555 
   440 DownloadController::DownloadController(
   556 DownloadController::DownloadController(
   441     const QString & client,
   557     const QString & /*client*/,
   442     const QNetworkProxy & proxy)
   558     const QNetworkProxy & /*proxy*/)
   443 {}
   559 {}
   444 
   560 
   445 DownloadController::~DownloadController()
   561 DownloadController::~DownloadController()
   446 {}
   562 {}
   447 
   563 
   463 {
   579 {
   464     QUrl url = request.url();
   580     QUrl url = request.url();
   465 
   581 
   466     emit unsupportedDownload(url);
   582     emit unsupportedDownload(url);
   467 }
   583 }
       
   584 
       
   585 void DownloadControllerPrivate::handleDownloadManagerEvent(
       
   586         DownloadManagerEvent * event)
       
   587 {
       
   588 }
       
   589 
       
   590 void DownloadControllerPrivate::handleDownloadEvent(
       
   591         DownloadEvent * event)
       
   592 {
       
   593 }
       
   594 
       
   595 DownloadControllerPrivate::~DownloadControllerPrivate()
       
   596 {}
   468 
   597 
   469 #endif // USE_DOWNLOAD_MANAGER
   598 #endif // USE_DOWNLOAD_MANAGER
   470 
   599 
   471 bool DownloadController::handlePage(QWebPage * page)
   600 bool DownloadController::handlePage(QWebPage * page)
   472 {
   601 {
   485         succeeded = false;
   614         succeeded = false;
   486     }
   615     }
   487 
   616 
   488     return succeeded;
   617     return succeeded;
   489 }
   618 }
   490