📄 phonetransferlogo.cpp
字号:
/*************************************************************************** phonetransferlogo.cpp - description ------------------- begin : Thu Jan 18 2001 copyright : (C) 2001 by Matthias Welwarsky email : matze@stud.fbi.fh-darmstadt.de ***************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/#include <kdebug.h>#include <klocale.h>#include <qlayout.h>#include <qgroupbox.h>#include <qprogressdialog.h>#include "messagedispatcher.h"#include "filebrowser.h"#include "phonetransferlogo.h"#include "phonectrlcenter.h"PhoneTransferLogo::PhoneTransferLogo(QWidget *parent, const char *name ) : PhoneTransferLogoDlg(parent,name), logoDataIterator(logoData){ PhoneCtrlCenter* pcCenter = dynamic_cast<PhoneCtrlCenter*>(parentWidget()); if (!pcCenter) { kdDebug() << "cannot resolve control center\n"; return; } messageDispatcher = pcCenter->getDispatcher(); // register the message types messageDispatcher->registerControl(this, QRegExp("\n\\^SBNR:")); messageDispatcher->registerControl(this, QRegExp("\n[0-9A-F]+")); messageDispatcher->registerControl(this, QRegExp("ERROR")); messageDispatcher->registerControl(this, QRegExp("\nOK")); messageDispatcher->registerControl(this, QRegExp("\n> ")); controlState = Idle; // embed the filebrowser into the container fileBrowserContainer->setOrientation(Horizontal); fileBrowserContainer->setColumns(1); fileBrowserContainer->layout()->setMargin(4); fileBrowserContainer->layout()->setSpacing(0); fileBrowser = new FileBrowser(fileBrowserContainer, "fileBrowser"); connect(fileBrowser, SIGNAL(selected(const QString&)), this, SLOT(setUploadLogo(const QString&))); fileBrowser->setDirectory(QDir::home()); connect(transferButton, SIGNAL(clicked()), this, SLOT(uploadLogo())); // the S35 can hold 2 logos, but only one is displayed // permanently. need more info bmpSubtype = 0; kdDebug() << "PhoneTransferLogo registered\n"; }PhoneTransferLogo::~PhoneTransferLogo(){}/** starts the transfer control, reimplemented from PhoneControl */void PhoneTransferLogo::startControl() { downloadLogo();}/** stops the transfer control, reimplemented from PhoneControl */void PhoneTransferLogo::stopControl(){ controlState = Idle;}/** reimplemented from PhoneControl */void PhoneTransferLogo::deliverMessage(QString message) { int len; int pos; switch(controlState) { case Idle: // ignore all unexpected messages break; case DownloadLogo: if (message.find(QRegExp("\n^SBNR:")) != -1) { pos = QRegExp("\\d+").match(message, 0, &len); pos = QRegExp("\\d+").match(message, pos+len, &len); expectNR = message.mid(pos, len).toInt(); pos = QRegExp("\\d+").match(message, pos+len, &len); maxNR = message.mid(pos, len).toInt(); if (expectNR == 1) progressDialog->setTotalSteps(maxNR); break; } if (message.find(QRegExp("\n[0-9A-F]+$")) != -1) { pos = QRegExp("[0-9A-F]+").match(message, 0, &len); TPDU* pdu = new TPDU(message.mid(pos, len)); logoData.append(pdu); progressDialog->setProgress(expectNR); if (expectNR == maxNR) { // fixme: the S25 has a different bitmap size and colors! QBitmap bitmap(100,40); bitmap = currentLogoData = TPDU::toByteArray(logoData); currentLogo->setPixmap(bitmap); delete progressDialog; controlState = Idle; } break; } case UploadLogo: if (message.find(QRegExp("\n> ")) != -1) { // phone awaits the next PDU messageDispatcher->sendPDU((*logoDataIterator)->toQString()); progressDialog->setProgress(expectNR); break; } if (message.find(QRegExp("\nOK")) != -1) { // phone has taken the PDU and awaits the next write command if (expectNR == maxNR) { // this was the last PDU for this entry delete progressDialog; controlState = Idle; messageDispatcher->sendCommand("ATE1"); break; } // send the next write command ++expectNR; ++logoDataIterator; QString command; command.sprintf("AT^SBNW=\"bmp\",%d,%d,%d", bmpSubtype, expectNR, maxNR); messageDispatcher->sendCommand(command); break; } if (message.find(QRegExp("ERROR")) != -1) { kdDebug() << "Error while uploading the logo\n"; controlState = Idle; delete progressDialog; messageDispatcher->sendCommand("ATE1"); break; } }}/** download the currently used logo from the mobile phone */void PhoneTransferLogo::downloadLogo() { logoData.clear(); controlState = DownloadLogo; QString command; command.sprintf("AT^SBNR=\"bmp\",%d", bmpSubtype); messageDispatcher->sendCommand(command); progressDialog = new QProgressDialog(this); progressDialog->setLabelText(i18n("Downloading..."));}/** loads the logo from the file with the name given by the argument */void PhoneTransferLogo::setUploadLogo(const QString& fileName){ kdDebug() << "setUploadLogo("<<fileName<<")\n"; QFile logoFile(fileName); logoFile.open(IO_ReadOnly); kdDebug() << "new logo has size " << logoFile.size() << endl; char *buffer = new char[logoFile.size()]; logoFile.readBlock(buffer, logoFile.size()); previewLogoData.assign(buffer, logoFile.size()); logoFile.close(); QBitmap bitmap(100,40); bitmap = previewLogoData; logoPreview->setPixmap(bitmap);}/** loads the logo currently stored in the preview into the mobile phone */void PhoneTransferLogo::uploadLogo() { // split the data into a list of TPDUs each containing 176 bytes maximum */ logoData = TPDU::split(previewLogoData, 176); // sanity check if (logoData.isEmpty()) return; logoDataIterator.toFirst(); controlState = UploadLogo; maxNR = logoData.count(); expectNR = 1; progressDialog = new QProgressDialog(this); progressDialog->setLabelText(i18n("Uploading...")); progressDialog->setTotalSteps(maxNR); QString command; command.sprintf("ATE0^SBNW=\"bmp\",%d,%d,%d", bmpSubtype, expectNR, maxNR); messageDispatcher->sendCommand(command);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -