void QGenieExport2DiskFileThread::run()
{
    if(
#ifdef PLATFORM_WIN32
       0 == setupapi_inf ||
       m_strnicguid.isEmpty() ||
#endif
       m_strssid.isEmpty() ||
       /*m_strprofilename_or_pwd.isEmpty() ||*/ m_strflashdisk.isEmpty())
    {
        emit export_completed(false);
        return;
    }

    bool bok = false;
#ifdef PLATFORM_WIN32
    QString  file_name = m_strflashdisk+EXPORT_TO_USB_FILENAME;

    if( QString("from router") == m_strnicguid)
    {
        //bok = setupapi_inf->export_to_file2(m_strssid,m_strprofilename_or_pwd,file_name);
        bok = setupapi_inf->export_to_file2_v2(m_strssid,m_strprofilename_or_pwd,m_auth,m_cipher,file_name);
     //   GeniePlugin_WSetupPlugin::output_log(QString("export wireless info from router"));
    }
    else
    {
        bok = setupapi_inf->export_to_file(m_strnicguid,m_strssid,m_strprofilename_or_pwd,file_name);
//        GeniePlugin_WSetupPlugin::output_log(QString("export wireless info from local"));
    }
#elif defined PLATFORM_MACOSX
    QString  file_name = QGenieMacOSXApi::get_save_path(m_strflashdisk,EXPORT_TO_USB_FILENAME);
    bok = QGenieMacOSXApi::export_to_file(m_strssid,m_strprofilename_or_pwd,
                                          m_auth,m_cipher,file_name);
//    GeniePlugin_WSetupPlugin::output_log(QString("export wireless info from router"));
#endif

    if(bok)
    {
        QString macx_filename;
#ifdef PLATFORM_WIN32
        file_name = m_strflashdisk+EXPORT_TO_USB_EXEFILENAME/*"GenieWirelessConfig.exe"*/;
        macx_filename = m_strflashdisk+EXPORT_TO_USB_MACXFILENAME;
#elif defined PLATFORM_MACOSX
        file_name = QGenieMacOSXApi::get_save_path(m_strflashdisk,EXPORT_TO_USB_EXEFILENAME);
        macx_filename = QGenieMacOSXApi::get_save_path(m_strflashdisk,EXPORT_TO_USB_MACXFILENAME);
#endif

        if(QFile::exists(file_name))
        {
            QFile::setPermissions(file_name,QFile::WriteOther);
            QFile::remove(file_name);
        }

        if(QFile::exists(macx_filename))
        {
            QFile::setPermissions(macx_filename,QFile::WriteOther);
            QFile::remove(macx_filename);
        }

        bok = (QFile::copy(QString(":/%1").arg(EXPORT_TO_USB_EXEFILENAME),file_name)
#ifdef WIRELESSIMPORT_MACX_SUPPORT
              /*&& QFile::copy(QString(":/%1").arg(EXPORT_TO_USB_MACXFILENAME),macx_filename)*/
               && copyMacOSAppBundle(m_strflashdisk)
#endif
              );

        if(bok)
        {
#ifdef PLATFORM_WIN32
            file_name = m_strflashdisk + EXPORT_TO_USB_INF;
#elif defined PLATFORM_MACOSX
            file_name = QGenieMacOSXApi::get_save_path(m_strflashdisk, EXPORT_TO_USB_INF);
#endif

            if(QFile::exists(file_name))
            {
                QFile::setPermissions(file_name,QFile::WriteOther);
                QFile::remove(file_name);
            }

            QFile::copy(QString(":/autorun.inf"),file_name);
        }
    }

    emit export_completed(bok);
}
Exemple #2
0
void Export::export_pdf(int columns)
{
    // 1200 dpi -> 200 dpi ~ 12pt font;
    // dims: 9583 x 13699

    int twelve_point = 200;
    int total_width = 9583;
    int total_height = 13699;
    int remaining_height = total_height;
    int puzzle_width = columns > 15 ? 6000 : 5000;
    int puzzle_height = puzzle_width;
    int clues_three_cols_width = total_width - puzzle_width;
    int clues_col_width_w_gap = clues_three_cols_width / 3;
    int col_gap = 225;  // empirically determined
    int clues_col_width = clues_col_width_w_gap - col_gap;
    int col_num = 1;

    //metadata
    QString title = qvariant_cast<QString>(m_metadata.takeAt(0));
    QString date = qvariant_cast<QString>(m_metadata.takeAt(0));
    QString author = qvariant_cast<QString>(m_metadata.takeAt(0));
    QString author_date = author + "          " + date;

    QRect title_rect(0, 0, total_width, (twelve_point * 2));
    remaining_height -= (twelve_point * 2);

    QPoint info_top_left(0, (title_rect.bottom() + 100));
    QSize author_date_size((total_width - puzzle_width), twelve_point);
    QRect author_date_rect(info_top_left, author_date_size);
    remaining_height -= (twelve_point + 100);

    //clues
    QPoint clues_col_top_left(0, (author_date_rect.bottom() + 300));
    remaining_height -= 300;
    QSize clues_col_size(clues_col_width, remaining_height);
    QRect whole_clues_col(clues_col_top_left, clues_col_size);
    QRect eaten_clues_col = whole_clues_col;

    //puzzles
    QImage puzzle = qvariant_cast<QImage>(m_images.takeAt(0));
    QImage puz_ans = qvariant_cast<QImage>(m_images.takeAt(0));
    QSize puz_size(puzzle_width, puzzle_height);
    QPoint puz_top_left((total_width - puzzle_width), title_rect.bottom());
    QRect puz_rect(puz_top_left, puz_size);
    QRect ans_rect(0, 0, (puzzle_width / 2), (puzzle_height / 2));

    //filepath
    QString base_path = QDir::homePath();
    QString file_name = title == "" ? "/untitled.pdf" : "/" + title + ".pdf";

    // PAINTING //
    QPdfWriter pdf(base_path + file_name);
    QPainter painter;

    // getting info on available space in the appropriate units (used for the seemingly random
    // numbers for the constants at the start of the function).
//    QPageLayout layout = pdf.pageLayout();
//    int resolution = pdf.resolution();
//    QRect printable_rect = layout.paintRectPixels(resolution);

    painter.begin(&pdf);

    // make the title
    QFont font = painter.font();
    font.setPixelSize(twelve_point * 2);
    font.setCapitalization(QFont::SmallCaps);
    painter.setFont(font);
    painter.drawText(title_rect, title);

    // make author and date
    font.setPixelSize(twelve_point / 2);
    font.setCapitalization(QFont::MixedCase);
    font.setItalic(true);
    painter.setFont(font);
    painter.drawText(author_date_rect, author_date);

    // across header
    font.setPixelSize(150);
    font.setBold(true);
    font.setItalic(false);
    painter.setFont(font);

    QString across_header = qvariant_cast<QString>(m_acrosses.takeAt(0));
    QRect space_needed = painter.boundingRect(eaten_clues_col, Qt::TextWordWrap, across_header);
    draw_clue(painter, eaten_clues_col, across_header, space_needed, Qt::AlignHCenter);
    eaten_clues_col.setTop(eaten_clues_col.top() + 100);  //ref: Export::paint_clues

    // across clues
    font.setBold(false);
    painter.setFont(font);
    paint_clues(painter, eaten_clues_col, m_acrosses, col_num, whole_clues_col, col_gap, puz_rect);

    // down header
    QVariantList down_header;
    down_header.append(m_downs.takeAt(0));  // is there a better way?

    font.setBold(true);
    painter.setFont(font);
    paint_clues(painter, eaten_clues_col, down_header, col_num, whole_clues_col,
                col_gap, puz_rect, Qt::AlignHCenter);

    // down clues
    font.setBold(false);
    painter.setFont(font);
    paint_clues(painter, eaten_clues_col, m_downs, col_num, whole_clues_col, col_gap, puz_rect);

    // images
    painter.drawImage(puz_rect, puzzle);
    pdf.newPage();
    painter.drawImage(ans_rect, puz_ans);

    painter.end();

    emit export_completed(file_name);
}