Advertisement
Guest User

.cpp

a guest
Oct 24th, 2011
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "beeliner.h"
  2. #include "ui_beeliner.h"
  3. //#include "ui_phones.h"
  4.  
  5. #include <QtGui>
  6.  
  7. BeelinerThread::BeelinerThread(QObject *parent) :
  8.     QThread(parent)
  9. {
  10.     //qDebug() << "BeelinerThread::BeelinerThread()" << QObject::thread();
  11. }
  12.  
  13. BeelinerThread::~BeelinerThread()
  14. {
  15.     //qDebug() << "BeelinerThread::~BeelinerThread()" << QObject::thread();
  16.     //wait();
  17.     //deleteLater();
  18. }
  19.  
  20. void BeelinerThread::run()
  21. {
  22.     //qDebug() << "Thread" << iter << QObject::thread();
  23.     QMutex mutex;
  24.     QString fileErrors = QDir::currentPath() + "/errors.txt";
  25.  
  26.     QElapsedTimer timer;
  27.     timer.start();
  28.  
  29.     QString phone = phonesForParsing[iter];
  30.  
  31.     QNetworkAccessManager qnam;
  32.     qnam.setCookieJar(new QNetworkCookieJar());
  33.     //qDebug() << &qnam << "start" << iter;
  34. //////////////////////////////////////////////////////////////////////////////////////////////////////////// Вход на сайт
  35.     QNetworkRequest request;
  36.     request.setRawHeader("User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)");
  37.     request.setUrl(QUrl("https://uslugi.beeline.ru/"));
  38.     QNetworkReply *reply = qnam.get(request);
  39.  
  40.     QEventLoop loop;
  41.     connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
  42.     loop.exec();
  43.  
  44.     reply->deleteLater();
  45.  
  46.     if(reply->error() != QNetworkReply::NoError) {
  47.         mutex.lock();
  48.         writeError(fileErrors, reply->errorString() + " getCookies " + phone + QDateTime::currentDateTime().toString(" dd.MM.yy H:mm:ss"));
  49.         mutex.unlock();
  50.     }
  51.     QString answer = QString::fromLocal8Bit(reply->readAll());
  52.  
  53.     QRegExp rx("<form name=\"EcareLoginForm\" method=\"post\" action=\"(.+)\"");
  54.     rx.setMinimal(true);
  55.     rx.indexIn(answer);
  56.  
  57.     QString sessionId = rx.cap(1);
  58.     QUrl url = QVariant("https://uslugi.beeline.ru" + sessionId).toUrl();
  59.  
  60. //////////////////////////////////////////////////// Login & Password ////////////////////////////////////////////////////////////////
  61.     QRegExp rxLogin("^(.+):(.+):");
  62.     rxLogin.setMinimal(true);
  63.     rxLogin.indexIn(phone);
  64.     QString login = rxLogin.cap(1);
  65.     QByteArray password = QTextCodec::codecForName("Windows-1251")->fromUnicode(rxLogin.cap(2)).toPercentEncoding();
  66. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  67.  
  68.     QString PostParams = "_stateParam=eCareLocale.currentLocale%3Dru_RU__Russian&_forwardName=null&_resetBreadCrumbs=false&_expandStatus=&userName=" + login + "&password=" + password + "&ecareAction=login";
  69.     QByteArray PostData = PostParams.toUtf8();
  70. //////////////////////////////////////////////////////////////////////////////////////////////////////////// Авторизация
  71.     request.setUrl(url);
  72.     reply = qnam.post(request, PostData);
  73.  
  74.     connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
  75.     loop.exec();
  76.  
  77.     reply->deleteLater();
  78.  
  79.     if(reply->error() != QNetworkReply::NoError) {
  80.         mutex.lock();
  81.         writeError(fileErrors, reply->errorString() + " authorization " + phone + QDateTime::currentDateTime().toString(" dd.MM.yy H:mm:ss"));
  82.         mutex.unlock();
  83.     }
  84.  
  85.     answer = QString::fromLocal8Bit(reply->readAll());
  86.  
  87.     if (answer.contains("Неправильный логин или пароль")) {
  88.         mutex.lock();
  89.         qint64 res = timer.elapsed();
  90.         qint64 sec = res / 1000;
  91.         qint64 min = sec / 60;
  92.         qint64 hr = min / 60;
  93.         sec %= 60;
  94.         min %= 60;
  95.  
  96.         QString timeElapsed = QString("%1:%2:%3").arg(hr).arg(min).arg(sec);
  97.  
  98.         model->insertRow(0);
  99.         model->setData(model->index(0, 0), phone);
  100.         model->setData(model->index(0, 1), QColor(Qt::red), Qt::ForegroundRole);
  101.         model->setData(model->index(0, 1), "Неправильный логин или пароль");
  102.         model->setData(model->index(0, 2), timeElapsed);
  103.         mutex.unlock();
  104.  
  105.         return;
  106.     } else if (answer.contains("Доступ к системе заблокирован")) {
  107.         mutex.lock();
  108.         qint64 res = timer.elapsed();
  109.         qint64 sec = res / 1000;
  110.         qint64 min = sec / 60;
  111.         qint64 hr = min / 60;
  112.         sec %= 60;
  113.         min %= 60;
  114.  
  115.         QString timeElapsed = QString("%1:%2:%3").arg(hr).arg(min).arg(sec);
  116.  
  117.         model->insertRow(0);
  118.         model->setData(model->index(0, 0), phone);
  119.         model->setData(model->index(0, 1), QColor(Qt::red), Qt::ForegroundRole);
  120.         model->setData(model->index(0, 1), "Доступ к системе заблокирован");
  121.         model->setData(model->index(0, 2), timeElapsed);
  122.         mutex.unlock();
  123.  
  124.         return;
  125.     } else {
  126.         QUrl redirectUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
  127. //////////////////////////////////////////////////////////////////////////////////////////////////////////// Редирект
  128.         request.setUrl(redirectUrl);
  129.         reply = qnam.get(request);
  130.  
  131.         connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
  132.         loop.exec();
  133.  
  134.         reply->deleteLater();
  135.     }
  136.  
  137.     if(reply->error() != QNetworkReply::NoError) {
  138.         mutex.lock();
  139.         writeError(fileErrors, reply->errorString() + " redirect " + phone + QDateTime::currentDateTime().toString(" dd.MM.yy H:mm:ss"));
  140.         mutex.unlock();
  141.     }
  142.  
  143.     answer = QString::fromLocal8Bit(reply->readAll());
  144.  
  145.     if (answer.contains("Система временно недоступна")) {
  146.         mutex.lock();
  147.         qint64 res = timer.elapsed();
  148.         qint64 sec = res / 1000;
  149.         qint64 min = sec / 60;
  150.         qint64 hr = min / 60;
  151.         sec %= 60;
  152.         min %= 60;
  153.  
  154.         QString timeElapsed = QString("%1:%2:%3").arg(hr).arg(min).arg(sec);
  155.  
  156.         model->insertRow(0);
  157.         model->setData(model->index(0, 0), phone);
  158.         model->setData(model->index(0, 1), QColor(Qt::red), Qt::ForegroundRole);
  159.         model->setData(model->index(0, 1), "Система временно недоступна");
  160.         model->setData(model->index(0, 2), timeElapsed);
  161.         mutex.unlock();
  162.  
  163.         return;
  164.     } else {
  165. //////////////////////////////////////////////////////////////////////////////////////////////////////////// Получение баланса (1 способ)
  166.         request.setUrl(QUrl("https://uslugi.beeline.ru/vip/prepaid/refreshedPrepaidBalance.jsp"));
  167.         reply = qnam.get(request);
  168.  
  169.         connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
  170.         loop.exec();
  171.  
  172.         reply->deleteLater();
  173.  
  174.         if(reply->error() != QNetworkReply::NoError) {
  175.             mutex.lock();
  176.             writeError(fileErrors, reply->errorString() + " redirect " + phone + QDateTime::currentDateTime().toString(" dd.MM.yy H:mm:ss"));
  177.             mutex.unlock();
  178.         }
  179.  
  180.         answer = QString::fromLocal8Bit(reply->readAll());
  181.  
  182.         QRegExp rxBalanseFast("<td class=\"tabred\">.+([0-9,]+)&nbsp;");
  183.         rxBalanseFast.setMinimal(true);
  184.         rxBalanseFast.indexIn(answer);
  185.         QString balanseFastStr = rxBalanseFast.cap(1);
  186.  
  187.         //qDebug() << balanseFastStr << iter;
  188.         //qDebug() << "fail count: " << failCount << iter;
  189.  
  190.         if (balanseFastStr.isEmpty()) {
  191.             if (failCount < 3) {
  192.                 failCount++;
  193.                 run();
  194.             } else {
  195.                 mutex.lock();
  196.                 qint64 res = timer.elapsed();
  197.                 qint64 sec = res / 1000;
  198.                 qint64 min = sec / 60;
  199.                 qint64 hr = min / 60;
  200.                 sec %= 60;
  201.                 min %= 60;
  202.  
  203.                 QString timeElapsed = QString("%1:%2:%3").arg(hr).arg(min).arg(sec);
  204.  
  205.                 model->insertRow(0);
  206.                 model->setData(model->index(0, 0), phone);
  207.                 model->setData(model->index(0, 1), QColor(Qt::red), Qt::ForegroundRole);
  208.                 model->setData(model->index(0, 1), "Не удалось спарсить баланс");
  209.                 model->setData(model->index(0, 2), timeElapsed);
  210.                 mutex.unlock();
  211.             }
  212.         } else {
  213.             mutex.lock();
  214.             double balanseFast = balanseFastStr.toDouble();            
  215.             qint64 res = timer.elapsed();
  216.             qint64 sec = res / 1000;
  217.             qint64 min = sec / 60;
  218.             qint64 hr = min / 60;
  219.             sec %= 60;
  220.             min %= 60;
  221.  
  222.             QString timeElapsed = QString("%1:%2:%3").arg(hr).arg(min).arg(sec);
  223.             //QString timeElapsed; QTextStream(&timeElapsed) << hr << ":" << min << ":" << sec;
  224.  
  225.             model->insertRow(0);
  226.             model->setData(model->index(0, 0), phone);
  227.  
  228.             QColor color;
  229.             if (balanseFast < 10) {
  230.                 color = Qt::red;
  231.             } else if (balanseFast > 10 && balanseFast < 50) {
  232.                 color = Qt::darkRed;
  233.             } else if (balanseFast > 50 && balanseFast < 100) {
  234.                 color = Qt::darkBlue;
  235.             } else {
  236.                 color = Qt::darkGreen;
  237.             }
  238.             model->setData(model->index(0, 1), QColor(color), Qt::ForegroundRole);
  239.  
  240.             model->setData(model->index(0, 1), balanseFast);
  241.             model->setData(model->index(0, 2), timeElapsed);
  242.             mutex.unlock();
  243.             //qDebug() << phone << balanse << "end";
  244.             //exec();
  245.             //qDebug() << "BeelinerThread::run() end";
  246.         }
  247.     }
  248.  
  249. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  250. //    if(reply->error() != QNetworkReply::NoError) {
  251. //        mutex.lock();
  252. //        writeError(fileErrors, reply->errorString() + " redirect " + phone + QDateTime::currentDateTime().toString(" dd.MM.yy H:mm:ss"));
  253. //        mutex.unlock();
  254. //    }
  255.  
  256. //    answer = QString::fromLocal8Bit(reply->readAll());
  257.  
  258. //    if (answer.contains("Система временно недоступна")) {
  259. //        mutex.lock();
  260. //        qint64 res = timer.elapsed();
  261. //        qint64 sec = res / 1000;
  262. //        qint64 min = sec / 60;
  263. //        qint64 hr = min / 60;
  264. //        sec %= 60;
  265. //        min %= 60;
  266.  
  267. //        QString timeElapsed = QString("%1:%2:%3").arg(hr).arg(min).arg(sec);
  268.  
  269. //        model->insertRow(0);
  270. //        model->setData(model->index(0, 0), phone);
  271. //        model->setData(model->index(0, 1), QColor(Qt::red), Qt::ForegroundRole);
  272. //        model->setData(model->index(0, 1), "Система временно недоступна");
  273. //        model->setData(model->index(0, 2), timeElapsed);
  274. //        mutex.unlock();
  275.  
  276. //        return;
  277. //    } else {
  278. //        QRegExp rx("effectiveDate=([^;]+);");
  279. //        rx.setMinimal(true);
  280. //        rx.indexIn(answer);
  281.  
  282. //        QString timestamp = rx.cap(1);
  283.  
  284. //        QString PostParams = "_navigation_secondaryMenu=PrepaidCTN.prepaidFinancialInfo&_resetBreadCrumbs=true&_stateParam=Reports.isNoneHierarchy%3Dfalse%3BnodeTypeNs%3Anull.pointLogicalId%3DCR_30%3BbreadCrumbs.breadCrumbDO1%3D0_%3BhierarchyTree%3AorgRepl.pointLogicalId%3D0%3BUsabilityNS%3Anull.pointLogicalId%3DnewUsability%3BTree%3AbillRepl.selected%3D0%3Bmulti-level%3Amenu.pointLogicalId%3D41%3BbreadCrumbs.breadCrumbsSize%3D1%3BeCareLocale.currentLocale%3Dru_RU__Russian%3BEntryNodes%3Areplica1.pointLogicalId%3D0%3BTree%3AorgRepl.selected%3D0%3BhierarchyTree%3AorgRepl.effectiveDate%3D" + timestamp + "%3BhierarchyTree%3AbillRepl.pointLogicalId%3D0%3BTree%3AorgRepl.treeExpandedList%3D3_%3BTree%3AbillRepl.treeExpandedList%3D4_%3BbackendSource%3Absource.backendsSourceName%3DENS%3Bhierarchies%3AhierarchiesRepl1.pointLogicalId%3D0&_expandStatus=";
  285. //        QByteArray PostData = PostParams.toUtf8();
  286. ////////////////////////////////////////////////////////////////////////////////////////////////////////////// Получение баланса (2 способ)
  287. //        request.setUrl(QUrl("https://uslugi.beeline.ru/VIPLoadPrepaidCtnFinancialInfoAction.do"));
  288. //        reply = qnam.post(request, PostData);
  289.  
  290. //        connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
  291. //        loop.exec();
  292.  
  293. //        reply->deleteLater();
  294. //    }
  295.  
  296. //    if(reply->error() != QNetworkReply::NoError) {
  297. //        mutex.lock();
  298. //        writeError(fileErrors, reply->errorString() + " financialInformation " + phone + QDateTime::currentDateTime().toString(" dd.MM.yy H:mm:ss"));
  299. //        mutex.unlock();
  300. //    }
  301.  
  302. //    answer = QString::fromLocal8Bit(reply->readAll());
  303.  
  304. //    QRegExp rxParsingBalanse("<td class='tabtext'>Основной баланс</td><td class='tabtext'>Рубли</td><td align='center' class='tabtext'>(.+)</td>");
  305. //    rxParsingBalanse.setMinimal(true);
  306. //    rxParsingBalanse.indexIn(answer);
  307. //    QString balanseStr = rxParsingBalanse.cap(1);
  308.  
  309. //    mutex.lock();
  310. //    double balanse = balanseStr.toDouble();
  311. //    qint64 res = timer.elapsed();
  312. //    qint64 sec = res / 1000;
  313. //    qint64 min = sec / 60;
  314. //    qint64 hr = min / 60;
  315. //    sec %= 60;
  316. //    min %= 60;
  317.  
  318. //    QString timeElapsed = QString("%1:%2:%3").arg(hr).arg(min).arg(sec);
  319. //    //QString timeElapsed; QTextStream(&timeElapsed) << hr << ":" << min << ":" << sec;
  320.  
  321. //    model->insertRow(0);
  322. //    model->setData(model->index(0, 0), phone);
  323.  
  324. //    QColor color;
  325. //    if (balanse < 10) {
  326. //        color = Qt::red;
  327. //    } else if (balanse > 10 && balanse < 50) {
  328. //        color = Qt::darkRed;
  329. //    } else if (balanse > 50 && balanse < 100) {
  330. //        color = Qt::darkBlue;
  331. //    } else {
  332. //        color = Qt::darkGreen;
  333. //    }
  334. //    model->setData(model->index(0, 1), QColor(color), Qt::ForegroundRole);
  335.  
  336. //    model->setData(model->index(0, 1), balanse);
  337. //    model->setData(model->index(0, 2), timeElapsed);
  338. //    mutex.unlock();
  339. //    //qDebug() << phone << balanse << "end";
  340. //    //exec();
  341. //    //qDebug() << "BeelinerThread::run() end";
  342. }
  343.  
  344. void BeelinerThread::writeError(QString fileName, QString data)
  345. {
  346.     QFile file(fileName);
  347.     file.open(QIODevice::Append);
  348.     QTextStream out(&file);
  349.     out << data << endl;
  350.     file.close();
  351. }
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358. Beeliner::Beeliner(QWidget *parent) :
  359.     QWidget(parent),
  360.     ui(new Ui::Beeliner)
  361. {
  362.     ui->setupUi(this);
  363.     QTextCodec *codec = QTextCodec::codecForName("UTF-8");
  364.     QTextCodec::setCodecForCStrings(codec);
  365.     QTextCodec::setCodecForTr(codec);
  366.  
  367.     model = new QStandardItemModel(0, 3, this);
  368.     model->setHorizontalHeaderLabels(QStringList() << "Номер" << "Баланс" << "Время парсинга");
  369.     ui->tableView->setModel(model);
  370.  
  371.     ui->tableView->setSortingEnabled(true);
  372.     ui->tableView->sortByColumn(1, Qt::DescendingOrder);
  373.  
  374.     ui->tableView->horizontalHeader()->resizeSection(0, 200);
  375.     ui->tableView->horizontalHeader()->resizeSection(1, 100);
  376.     ui->tableView->horizontalHeader()->setStretchLastSection(true);
  377.  
  378.     QString progDir = QDir::currentPath();
  379.     filePhones = progDir + "/logins.txt";
  380.     fileErrors = progDir + "/errors.txt";
  381.     QFile file(filePhones);
  382.     file.open(QIODevice::ReadOnly);
  383.     QTextStream in(&file);
  384.  
  385.     QStringList phonesNoClear;
  386.     while (!in.atEnd()) {
  387.         phonesNoClear.append(in.readLine());
  388.     }
  389.     file.close();
  390.  
  391.     phones = phonesNoClear.filter(QRegExp("^[0-9]+.+$"));
  392.  
  393.     QString buttonLabel = "Телефоны   " + QString::number(phones.count()) + "(" + QString::number(phones.count()) + ")";
  394.     ui->pushButtonPhones->setText(buttonLabel);
  395.  
  396.     phonesDialog = 0;
  397. }
  398.  
  399. Beeliner::~Beeliner()
  400. {
  401.     delete ui;
  402.     delete model;
  403. }
  404.  
  405.  
  406.  
  407. void Beeliner::on_pushButtonPhones_clicked()
  408. {
  409.     if (phonesDialog == 0) {
  410.         phonesDialog = new QDialog(this);
  411.  
  412.         uiPhones.setupUi(phonesDialog);
  413.  
  414.         modelPhones = new QStandardItemModel(0, 1, this);
  415.         modelPhones->setHorizontalHeaderItem(0, new QStandardItem("Телефоны"));
  416.         uiPhones.tableViewPhones->setModel(modelPhones);
  417.         uiPhones.tableViewPhones->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
  418.         uiPhones.tableViewPhones->setShowGrid(false);
  419.         uiPhones.tableViewPhones->verticalHeader()->setDefaultSectionSize(20);
  420.  
  421.         for (int i = 0; i < phones.count(); i++) {
  422.             QStandardItem *item = new QStandardItem(phones[i]);
  423.             item->setCheckable(true);
  424.             item->setCheckState(Qt::Checked);
  425.             item->setEditable(true);
  426.             modelPhones->setItem(i, item);
  427.         }
  428.  
  429.         uiPhones.checkBoxAll->setCheckState(Qt::Checked);
  430.  
  431.         connect(uiPhones.checkBoxAll, SIGNAL(stateChanged(int)), this, SLOT(ckeckAll(int)));
  432.         connect(modelPhones, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(addPhoneForParsing(QStandardItem*)));
  433.         connect(uiPhones.pushButtonAdd, SIGNAL(clicked()), this, SLOT(addPhone()));
  434.         connect(uiPhones.pushButtonDelete, SIGNAL(clicked()), this, SLOT(deletePhone()));
  435.         connect(uiPhones.pushButtonChange, SIGNAL(clicked()), this, SLOT(changePhone()));
  436.  
  437.         phonesDialog->exec();
  438.     } else {
  439.         phonesDialog->exec();
  440.     }
  441. }
  442.  
  443. void Beeliner::addPhoneForParsing(QStandardItem *item)
  444.  {
  445.     if (item->checkState() == 2) {
  446.         phonesForParsing << item->text();
  447.     } else {
  448.         phonesForParsing.removeOne(item->text());
  449.     }
  450.     phonesForParsing.removeDuplicates();
  451.     phonesForParsing = phonesForParsing.filter(QRegExp("[^0]+"));
  452.  
  453.     QString buttonLabel = "Телефоны   " + QString::number(phonesForParsing.count()) + "(" + QString::number(phones.count()) + ")";
  454.     ui->pushButtonPhones->setText(buttonLabel);
  455.  }
  456.  
  457. void Beeliner::ckeckAll(int state)
  458. {
  459.     if (phones.isEmpty()) {
  460.         QMessageBox::information(phonesDialog, tr("Косяк"), tr("Нече выделять"));
  461.     } else {
  462.         if (state == 0) {
  463.             for (int i = 0; i < phones.count(); i++) {
  464.                 modelPhones->item(i)->setCheckState(Qt::Unchecked);
  465.                 phonesForParsing << "0";
  466.                 phonesForParsing.removeDuplicates();
  467.             }
  468.         } else {
  469.             for (int i = 0; i < phones.count(); i++) {
  470.                 modelPhones->item(i)->setCheckState(Qt::Checked);
  471.             }
  472.         }
  473.     }
  474. }
  475.  
  476. void Beeliner::addPhone()
  477. {
  478.     bool ok;
  479.     QString text = QInputDialog::getText(phonesDialog, tr("Введи номер"),
  480.                                        tr("Номер:"), QLineEdit::Normal,
  481.                                        tr("телефон:пароль:город"), &ok);
  482.  
  483.    if (ok && !text.isEmpty()) {
  484.        QRegExp rx("^[0-9]+.+$");
  485.        if (rx.exactMatch(text)) {
  486.            QStandardItem *item = new QStandardItem(text);
  487.            item->setCheckable(true);
  488.            item->setEditable(true);
  489.            modelPhones->setItem(phones.count(), item);
  490.  
  491.            phones << text;
  492.  
  493.            writePhones(filePhones, phones);
  494.  
  495.            QString buttonLabel = "Телефоны   " + QString::number(phonesForParsing.count()) + "(" + QString::number(phones.count()) + ")";
  496.            ui->pushButtonPhones->setText(buttonLabel);
  497.        } else {
  498.            QMessageBox::information(phonesDialog, tr("Косяк"), tr("Неверный формат!"));
  499.        }
  500.    }
  501. }
  502.  
  503. void Beeliner::deletePhone()
  504. {
  505.     if (!uiPhones.tableViewPhones->selectionModel()->selectedRows().isEmpty()) {
  506.  
  507.         if (QMessageBox::question(phonesDialog, tr("Удаление номера"), tr("Удалить?"),
  508.                                 QMessageBox::Yes, QMessageBox::No ) == QMessageBox::No)
  509.              return;
  510.         else {
  511.             int count = uiPhones.tableViewPhones->selectionModel()->selectedRows().count();
  512.             for (int i = 0; i < count; ++i) {
  513.                 phones.removeOne(uiPhones.tableViewPhones->selectionModel()->selectedRows().at(0).data().toString());
  514.                 if (phonesForParsing.contains(uiPhones.tableViewPhones->selectionModel()->selectedRows().at(0).data().toString())) {
  515.                     phonesForParsing.removeOne(uiPhones.tableViewPhones->selectionModel()->selectedRows().at(0).data().toString());
  516.                 }
  517.                 modelPhones->removeRow(uiPhones.tableViewPhones->selectionModel()->selectedRows().at(0).row(), QModelIndex());
  518.             }
  519.  
  520.             QString buttonLabel = "Телефоны   " + QString::number(phonesForParsing.count()) + "(" + QString::number(phones.count()) + ")";
  521.             ui->pushButtonPhones->setText(buttonLabel);
  522.  
  523.             writePhones(filePhones, phones);
  524.             if (phones.isEmpty()){
  525.                 QFile::remove(filePhones);
  526.             }
  527.         }
  528.     } else if (phones.isEmpty()) {
  529.         QMessageBox::information(phonesDialog, tr("Косяк"), tr("Нече удалять"));
  530.     } else {
  531.         QMessageBox::information(phonesDialog, tr("Косяк"), tr("Надо выделить номер!"));
  532.     }
  533. }
  534.  
  535. void Beeliner::changePhone()
  536. {
  537.     if (phones.isEmpty()) {
  538.         QMessageBox::information(phonesDialog, tr("Косяк"), tr("Нече изменять")); return;
  539.     } else if (uiPhones.tableViewPhones->selectionModel()->selectedRows().count() == 0){
  540.         QMessageBox::information(phonesDialog, tr("Косяк"), tr("Надо выделить номер!")); return;
  541.     }
  542.  
  543.     bool ok;
  544.     QString text = QInputDialog::getText(phonesDialog, tr("Введи номер"),
  545.                                        tr("Номер:"), QLineEdit::Normal,
  546.                                        uiPhones.tableViewPhones->selectionModel()->selectedRows().at(0).data().toString(), &ok);
  547.     if (ok && !text.isEmpty()) {
  548.         QRegExp rx("^[0-9]+.+$");
  549.         if (rx.exactMatch(text)) {
  550.             modelPhones->item(uiPhones.tableViewPhones->selectionModel()->selectedRows().at(0).row())->setText(text);
  551.             phones.replace(uiPhones.tableViewPhones->selectionModel()->selectedRows().at(0).row(), text);
  552.             writePhones(filePhones, phones);
  553.         } else {
  554.             QMessageBox::information(phonesDialog, tr("Косяк"), tr("Неверный формат!"));
  555.         }
  556.     } else {
  557.  
  558.     }
  559. }
  560.  
  561.  
  562.  
  563. void Beeliner::on_pushButton_clicked()
  564. {
  565.     ui->labelResult->setText("Старт!");
  566.     if (phones.isEmpty()) {
  567.         QMessageBox::information(this, tr("Косяк"),
  568.                                  tr("Нет телефонов для парсинга"));
  569.         return;
  570.     }
  571.     if (model->rowCount() > 0) {
  572.         model->insertRows(0, 3);
  573.         //model->removeRows(0, model->rowCount());
  574.     }
  575.  
  576.     if (phonesForParsing.isEmpty()) {
  577.         phonesForParsing = phones;
  578.     } else if (phonesForParsing[0] == "0") {
  579.         QMessageBox::information(phonesDialog, tr("Косяк"), tr("Не выбраны телефоны для парсинга"));
  580.         return;
  581.     }
  582.  
  583.     result = 0;
  584.     for (int i = 0; i < phonesForParsing.count(); i++) {
  585.         BeelinerThread *getBalanse = new BeelinerThread(this);
  586.         getBalanse->iter = i;
  587.         getBalanse->failCount = 0;
  588.         getBalanse->phonesForParsing = phonesForParsing;
  589.         getBalanse->model = model;
  590.         getBalanse->start();
  591.  
  592.         connect(getBalanse, SIGNAL(finished()), this, SLOT(resultCount()));
  593.  
  594.         //connect(getBalanse, SIGNAL(finished()), getBalanse, SLOT(deleteLater()));
  595.         //getBalanse->wait();
  596.         //delete getBalanse;
  597.         //getBalanse->deleteLater();
  598.     }
  599.  
  600.  
  601.  
  602. }
  603.  
  604. void Beeliner::writePhones(QString fileName, QStringList list)
  605. {
  606.     QString str = list.join("\r\n");
  607.     QFile file(fileName);
  608.     file.open(QIODevice::WriteOnly);
  609.     QTextStream out(&file);
  610.     out << str;
  611.     file.close();
  612. }
  613.  
  614. void Beeliner::resultCount()
  615. {
  616.     result++;
  617.     QString resultStr;
  618.     if (result < phonesForParsing.count()) {
  619.         resultStr = QString::number(result);
  620.     } else {
  621.         resultStr = QString::number(result) + " <span style=color:green;>Готово!</span>";
  622.     }
  623.     ui->labelResult->setText(resultStr);
  624. }
  625.  
  626.  
  627.  
  628.  
  629. //    QList<QNetworkCookie> cookiesTest = cookieJar->getAllCookies();
  630. //    qDebug() << cookiesTest;
  631. //    qDebug() << cookieJar; //return;
  632.  
  633. //    qDebug() << cookieJar;
  634. //    QNetworkRequest requestt = reply->request();
  635. //    qDebug() << "Request headers:  ";
  636. //    QList<QByteArray> reqHeaders = requestt.rawHeaderList();
  637. //    foreach( QByteArray reqName, reqHeaders )
  638. //    {
  639. //        QByteArray reqValue = requestt.rawHeader( reqName );
  640. //        qDebug() << reqName << ": " << reqValue;
  641. //    }
  642.  
  643.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement