示例#1
0
/**
 * Event which is sent when a drag and drop action is completed
 * @param event Event
 */
void MainWindow::dropEvent(QDropEvent *event)
{
    if ( !ui->textEdit_mainWindow_surface->toPlainText().isEmpty() ) {
        QMessageBox::StandardButton reply;
          reply = QMessageBox::question(this, tr("Confirmation"), tr("The content is not empty. Are you sure?"),
                                        QMessageBox::Yes|QMessageBox::No);
          if (reply == QMessageBox::Yes) {
              QString file;
              QList<QUrl> urls;
              QList<QUrl>::Iterator i;
              urls = event->mimeData()->urls();
              for (i = urls.begin(); i != urls.end(); ++i)
              {
                  file = i->toLocalFile();
                  QString text = getFileContent(file);
                  ui->textEdit_mainWindow_surface->setHtml(text);
              }
          } else {
            return;
          }
    } else {
        QString file;
        QList<QUrl> urls;
        QList<QUrl>::Iterator i;
        urls = event->mimeData()->urls();
        for (i = urls.begin(); i != urls.end(); ++i)
        {
            file = i->toLocalFile();
            QString text = getFileContent(file);
            ui->textEdit_mainWindow_surface->setHtml(text);
        }
    }
}
示例#2
0
//
// Method looks for animationName_Sheet.xml and animationName_Anim.xml files
// if it finds them than it parses files and fills two vectors
// sprites and animations
//
F2EAnimation::F2EAnimation(const char *animationName)
{
    m_name = string(animationName);
    
    m_parser = std::shared_ptr<F2EParser>(new F2EParser());
    
    string fileName = m_name + string("_Sheet.xml");
    string buffer = getFileContent(fileName.c_str());
    
    if (buffer[0] != '\0')
        m_parser->parseSprites(buffer, sprites);
    else {
#ifdef F2E_DEBUG
        std::cout << "F2EAnimation error: couldn't find sprites sheet xml file" << std::endl;
#endif
    }
    
    fileName.clear();
    buffer.clear();
    
    fileName = m_name + string("_Anim.xml");
    buffer = getFileContent(fileName.c_str());
    
    if (buffer[0] != '\0')
        framesCount = m_parser->parseAnimations(buffer, animations);
    else {
#ifdef F2E_DEBUG
        std::cout << "F2EAnimtion error: couldn't find animations xml file" << std::endl;
#endif
    }
}
示例#3
0
//-------------------------------------------------------------------------
bool QGuidoPainter::setGMNFile(const QString& fileName)
{
	bool result = setGMNData( fileName , GuidoParseFile );
	mFileName = fileName;
	mGMNCode = getFileContent(fileName);
	return result;
}
void SubToolBar::initTextLabel() {
    //text...
    m_textLabel = new QLabel(this);
    m_textLabel->setStyleSheet(getFileContent(":/resources/qss/textbutton.qss"));
    QList<int> fontSizeList;
    fontSizeList << 9 << 10 << 12 << 14 << 18 << 24 << 36 << 48 << 64 << 72 << 96;
    QButtonGroup* textBtnGroup = new QButtonGroup(this);

    QList<TextButton*> textButtonList;
    for(int i = 0; i < fontSizeList.length(); i++) {
        TextButton* textButton = new TextButton(fontSizeList[i], m_textLabel);
        textBtnGroup->addButton(textButton);
        textButtonList.append(textButton);
    }
    textBtnGroup->setExclusive(true);
      int defaultFontSize = ConfigSettings::instance()->value("text", "fontsize").toInt();

    QHBoxLayout* textLayout = new QHBoxLayout();
    textLayout->setMargin(0);
    textLayout->setSpacing(0);
    textLayout->addSpacing(1);
    for(int k = 0; k < textButtonList.length(); k++) {
        textLayout->addWidget(textButtonList[k]);
        textLayout->addSpacing(BUTTON_SPACING);
        if (fontSizeList[k] == defaultFontSize) {
            textButtonList[k]->setChecked(true);
        }
    }
    textLayout->addStretch();
    m_textLabel->setLayout(textLayout);
    addWidget(m_textLabel);
}
void
ModulePackageContainer::add(DnfSack * sack)
{
    Pool * pool = dnf_sack_get_pool(sack);
    LibsolvRepo * r;
    Id id;

    FOR_REPOS(id, r) {
        HyRepo hyRepo = static_cast<HyRepo>(r->appdata);
        auto modules_fn = hy_repo_get_string(hyRepo, MODULES_FN);
        if (!modules_fn) {
            continue;
        }
        std::string yamlContent = getFileContent(modules_fn);
        auto repoName = hy_repo_get_string(hyRepo, HY_REPO_NAME);
        add(yamlContent, repoName);
        // update defaults from repo
        try {
            pImpl->defaultConteiner.fromString(yamlContent, 0);
        } catch (const ModuleDefaultsContainer::ConflictException & exception) {
            throw ModuleDefaultsContainer::ConflictException(
                tfm::format(_("Conflicting defaults with repo '%s': %s"), repoName,
                            exception.what()));
        }
    }
示例#6
0
Menu::Menu(TeamHolder *t) :
    ui(new Ui::Menu), team(t)
{
    ui->setupUi(this);
    ui->appLogo->setPixmap(Theme::Sprite("logo"));
    ui->updateContainer->hide();
    ui->stackedWidget->setCurrentIndex(1);

    setWindowTitle(tr("Menu"));

    connect (ui->teamBuilder, SIGNAL(clicked()), SIGNAL(goToTeambuilder()));
    connect (ui->goOnline, SIGNAL(clicked()), SIGNAL(goToOnline()));
    connect (ui->credits, SIGNAL(clicked()), SIGNAL(goToCredits()));
    connect (ui->exit, SIGNAL(clicked()), SIGNAL(goToExit()));
    connect (ui->updateButton, SIGNAL(clicked()), SIGNAL(downloadUpdateRequested()));
    connect (ui->prevTip, SIGNAL(clicked()), SLOT(prevTip()));
    connect (ui->nextTip, SIGNAL(clicked()), SLOT(nextTip()));

    srand(time(NULL));

    msgs = QString::fromUtf8(getFileContent("db/tips.txt")).trimmed().split("\n");

    currentTip = rand()%(msgs.size());
    updateTip();

    if (!menuLoaded) {
        loadSettings(this);
    }
}
示例#7
0
文件: reorg.c 项目: hsantham/mcgpu
int main() {
	unsigned int indexOrder[MAX_INDEXES];
	unsigned int used;
	getOrderFromFile(indexOrder, &used);
	unsigned int chunksize = indexOrder[used-1];
	used--;
	
    unsigned char  *unziped   = "compressed_file_with_mc_gzip";
	unsigned char *hostFileBuffer;
	unsigned long long int filesize = getFilesize(unziped);
	hostFileBuffer = (unsigned char *) malloc(filesize+1);
    getFileContent(unziped, hostFileBuffer);
	
	FILE *file;
    file = fopen((const char *)"decompressed_file", "w");
    assert(file != NULL);

    for(int i = 0; i < used; i++) {
        unsigned int jumbledPos = getPosof(indexOrder, used, i);
        unsigned int lastChunkPos = getPosof(indexOrder, used, used-1);
        unsigned int bytesToWrite = min(chunksize, filesize - i * chunksize);
        unsigned int offset = 0;
        if(lastChunkPos < jumbledPos) {
            offset =  chunksize - min(chunksize, filesize - (used-1) * chunksize);
        }
        unsigned int written = fwrite(hostFileBuffer + jumbledPos * chunksize - offset, 1, bytesToWrite, file);
        assert(written == bytesToWrite);
        assert(ferror(file) == 0);
    }

    fclose(file);
	return 0;
}
示例#8
0
文件: Project.cpp 项目: hzx/mutant
int Project::load() {
  std::string curdir = getCurrentDir();
  std::string abspath = getRealPath(curdir);
  char buf[PATH_MAX];

  for (;;) {
    if (curdir.length() < MIN_PROJECT_PATH_LENGTH) {
      return -1; // error
    }

    std::string proj = curdir + PROJECT_FILENAME;
    if (existsFile(proj)) {
      filename = proj;
      content = getFileContent(proj);
      dir = curdir;
      return  0; // ok
    }

    // copy curdir to buf for, api compatibility
    memcpy(buf, curdir.c_str(), curdir.length());
    buf[curdir.length()] = '\0';

    curdir = dirname(buf);
  }

  return -1; // error
}
void SubToolBar::initColorLabel() {
    m_colorLabel = new QLabel(this);
    m_colorLabel->setStyleSheet(getFileContent(":/resources/qss/colorbtn.qss"));
    QList<ColorButton*> colorBtnList;
    QButtonGroup* colorBtnGroup = new QButtonGroup(m_colorLabel);
    colorBtnGroup->setExclusive(true);

    for(int i = 0; i < COLOR_NUM; i ++) {
        ColorButton* colorBtn = new ColorButton(colorIndexOf(i));
        colorBtn->setObjectName(QString("ColorBtn%1").arg(i+1));
        colorBtnList.append(colorBtn);
        colorBtnGroup->addButton(colorBtn);
    }

    QHBoxLayout* colorLayout = new QHBoxLayout();
    colorLayout->setMargin(0);
    colorLayout->setSpacing(0);
    colorLayout->addSpacing(3);
    for(int i = 0; i < colorBtnList.length(); i++) {
        colorLayout->addWidget(colorBtnList[i]);
        colorLayout->addSpacing(1);
        connect(colorBtnList[i], &ColorButton::updatePaintColor,
                this, &SubToolBar::updateColor);
    }
    colorLayout->addStretch();
    m_colorLabel->setLayout(colorLayout);

    addWidget(m_colorLabel);

    connect(this, &SubToolBar::defaultColorIndexChanged, this, [=](int index){
        colorBtnList[index]->setChecked(true);
    });
}
示例#10
0
static int load_file_contents()
{
	int i;
	int result;
	int64_t file_size;

	for (i=0; i<FILE_TYPE_COUNT; i++)
	{
		if ((result=getFileContent(files[i].filename, &(files[i].file_buff), &file_size)) != 0)
		{
			printf("file: "__FILE__", line: %d, " 
				"getFileContent %s fail, errno: %d, error info: %s\n", __LINE__, 
				files[i].filename, errno, strerror(errno));

			return result;
		}

		if (file_size != files[i].bytes)
		{
			printf("file: "__FILE__", line: %d, " 
				"%s file size: %d != %d\n", __LINE__, 
				files[i].filename, (int)file_size, files[i].bytes);

			return EINVAL;
		}
	}

	return 0;
}
示例#11
0
/**
 * Opens a document and checks its format
 */
void MainWindow::on_actionOpen_triggered()
{
    QString file = QFileDialog::getOpenFileName(this, tr("Open Document"), QDir::home().absolutePath(), "text files (*.sb)");
    if ( !file.isEmpty() ) {
        QString text = getFileContent(file);
        ui->textEdit_mainWindow_surface->setHtml(text);
    } else {
        return;
    }

}
示例#12
0
文件: DptfStatus.cpp 项目: 01org/dptf
std::string DptfStatus::getXsltContent(eEsifError* returnCode)
{
	try
	{
		return getFileContent(m_dptfManager->getDptfHomeDirectoryPath() + "combined.xsl");
	}
	catch (dptf_exception&)
	{
		// Could not find file, try from Resources/
		*returnCode = ESIF_E_UNSPECIFIED;
		throw;
	}
}
int
searchServerInfo(char* progName, char* serverAddress, char*  serverPort)
{




    /* Nom du fichier demandé */
    char* filename;

    /* Déclaration de la liste chainée contenant les noms des fichiers disponibles*/
    list ma_liste = NULL;



    /* Set connection with server */
    sockcli = sockConnect(serverAddress, serverPort);



    /* Get list of available files from server */
    ma_liste = getFilenameList(sockcli);


    /* Boucle infinie */
    while (true) {

        /* Print list of available files */
        printf("\n\n	 Fichiers disponibles\n\n");
        print_list(ma_liste);
        printf("\n");


        /* Select one file from the list */
        filename = menu_choice(ma_liste);


        /* Send the requested file to the server. */
        sendFilename(filename);


        /* Receive the file content from the server. */
        getFileContent(progName, filename, sockcli);

    }

    printf("\n[%ld] Fermeture de la socket.\n\n \n", (long int) getpid());
    close(sockcli);

    return EXIT_SUCCESS;
}
void SubToolBar::initWidget() {
//    setObjectName("SubToolBar");
    setStyleSheet(getFileContent(":/resources/qss/subtoolbar.qss"));
    setFixedSize(TOOLBAR_WIDTH, TOOLBAR_HEIGHT);

    initRectLabel();
    initArrowLabel();
    initLineLabel();
    initTextLabel();
    initColorLabel();
    initSaveLabel();

    setCurrentWidget(0);
}
示例#15
0
int ApplicationData::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: { QString _r = getFileContent((*reinterpret_cast< QString(*)>(_a[1])));
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r; }  break;
        default: ;
        }
        _id -= 1;
    }
    return _id;
}
示例#16
0
bool QDropboxFile::open(QIODevice::OpenMode mode)
{
#ifdef QTDROPBOX_DEBUG
    qDebug() << "QDropboxFile::open(...)" << endl;
#endif
    if(!QIODevice::open(mode))
        return false;

  /*  if(isMode(QIODevice::NotOpen))
        return true; */

    if(_buffer == NULL)
        _buffer = new QByteArray();

#ifdef QTDROPBOX_DEBUG
    qDebug() << "QDropboxFile: opening file" << endl;
#endif

	// clear buffer and reset position if this file was opened in write mode
	// with truncate - or if append was not set
	if(isMode(QIODevice::WriteOnly) && 
	   (isMode(QIODevice::Truncate) || !isMode(QIODevice::Append))
	  )
    {
#ifdef QTDROPBOX_DEBUG
    qDebug() << "QDropboxFile: _buffer cleared." << endl;
#endif
        _buffer->clear();
		_position = 0;
    }
    else
    {
#ifdef QTDROPBOX_DEBUG
    qDebug() << "QDropboxFile: reading file content" << endl;
#endif
        if(!getFileContent(_filename))
            return false;

		if(isMode(QIODevice::WriteOnly)) // write mode here means append
			_position = _buffer->size();
		else if(isMode(QIODevice::ReadOnly)) // read mode here means start at the beginning
			_position = 0;
    }

	obtainMetadata();		 

    return true;
}
示例#17
0
static int iniDoLoadFromFile(const char *szFilename, \
                             IniContext *pContext)
{
    char *content;
    int result;
    int http_status;
    int content_len;
    int64_t file_size;
    char error_info[512];

    if (strncasecmp(szFilename, "http://", 7) == 0)
    {
        if ((result=get_url_content(szFilename, 10, 60, &http_status, \
                                    &content, &content_len, error_info)) != 0)
        {
            logError("file: "__FILE__", line: %d, " \
                     "get_url_content fail, " \
                     "url: %s, error info: %s", \
                     __LINE__, szFilename, error_info);
            return result;
        }

        if (http_status != 200)
        {
            free(content);
            logError("file: "__FILE__", line: %d, " \
                     "HTTP status code: %d != 200, url: %s", \
                     __LINE__, http_status, szFilename);
            return EINVAL;
        }
    }
    else
    {
        if ((result=getFileContent(szFilename, &content, \
                                   &file_size)) != 0)
        {
            return result;
        }
    }

    result = iniDoLoadItemsFromBuffer(content, pContext);
    free(content);

    return result;
}
示例#18
0
ToolBarWidget::ToolBarWidget(QWidget *parent)
    :DBlurEffectWidget(parent),
      m_expanded(false)
{
    setStyleSheet(getFileContent(":/resources/qss/toolbar.qss"));
    setBlurRectXRadius(3);
    setBlurRectYRadius(3);
    setRadius(30);
    setMaskColor(QColor(255, 255, 255, 204));
    setFixedSize(TOOLBAR_WIDGET_SIZE);

    qDebug() << "~~~~~~" << this->size();
    m_hSeparatorLine = new QLabel(this);
    m_hSeparatorLine->setObjectName("HorSeparatorLine");
    m_hSeparatorLine->setFixedHeight(1);

    m_majToolbar = new MajToolBar(this);
    m_subToolbar = new SubToolBar(this);

    QVBoxLayout* vLayout = new QVBoxLayout();
    vLayout->setMargin(0);
    vLayout->setSpacing(0);
    vLayout->addWidget(m_majToolbar, 0, Qt::AlignVCenter);
    vLayout->addWidget(m_hSeparatorLine, 0, Qt::AlignVCenter);
    vLayout->addWidget(m_subToolbar, 0, Qt::AlignVCenter);
    setLayout(vLayout);

    m_hSeparatorLine->hide();
    m_subToolbar->hide();

    connect(m_majToolbar, &MajToolBar::buttonChecked, this, &ToolBarWidget::setExpand);
    connect(m_majToolbar, &MajToolBar::saveImage, this, &ToolBarWidget::saveImage);
    connect(m_subToolbar, &SubToolBar::saveAction, this, &ToolBarWidget::saveImage);

    connect(m_subToolbar, &SubToolBar::currentColorChanged, this, &ToolBarWidget::colorChanged);
    connect(m_subToolbar, &SubToolBar::currentColorChanged,  m_majToolbar, &MajToolBar::mainColorChanged);

    connect(m_subToolbar, &SubToolBar::showSaveTip, m_majToolbar, &MajToolBar::showSaveTooltip);
    connect(m_subToolbar, &SubToolBar::hideSaveTip, m_majToolbar, &MajToolBar::hideSaveTooltip);

    connect(this, &ToolBarWidget::shapePressed, m_majToolbar, &MajToolBar::shapePressed);
    connect(this, &ToolBarWidget::saveBtnPressed, m_subToolbar, &SubToolBar::saveBtnPressed);
    connect(m_majToolbar, &MajToolBar::saveSpecificedPath, this, &ToolBarWidget::saveSpecifiedPath);
    connect(m_majToolbar, &MajToolBar::closed, this, &ToolBarWidget::closed);
}
示例#19
0
/*Send OK Function
  Variable Definition:
  -- url: the request url except domain name and port number
  -- method: the request method
  -- client_socket: socket connected to the client
  Return Value: NULL
*/
void sendOK(char *url, const char *method, int client_socket){
	char 	*extension = getFileType(url);										//file extension
	char 	*type = "text/html";												//file type
	char	*entity_body = (char*)malloc(sizeof(char) * (FILE_SIZE + 1));		//entity body
	FILE 	*out_channel;														//file stream to client socket
	int 	file_length = 0;													//file length
	int 	bytes = 0;															//bytes that has sent
	
	//Set the value of Content-Type
	if (strcmp(extension, "txt") == 0){
		type = "text/plain";
	}
	else if (strcmp(extension, "gif") == 0){
		type = "image/gif";
	}
	else if (strcmp(extension, "jpg") == 0){
		type = "image/jpeg";
	}
	else if (strcmp(extension, "jpeg") == 0){
		type = "image/jpeg";
	}
	
	//Create an output stream to the socket
	out_channel = fdopen(client_socket, "w");
	if (out_channel != NULL){
		//Get the request file content and file length
		file_length = getFileContent(url, entity_body);
		//HEAD request does not Response entity body
		if (strcmp(method, "HEAD") == 0){
			entity_body = NULL;
		}
		//Send Response Message to client
		bytes = constructResponseMessage(	client_socket,
											&out_channel,
											200,
											"OK",
											convertTimeFormat(getTimeInGMTFormat(url, 2), 1),
											file_length,
											type,
											entity_body);
		//Close file stream
		fclose(out_channel);
	}
}
示例#20
0
void decodeMessage() {
    char *encodedMessage = getFileContent("encodedText.txt");
    if (encodedMessage == NULL) {
        return;
    }

    char *strStripped = getCompressedKey("lyrics.txt");
    if (strStripped == NULL) {
        return;
    }

    char resStr[strlen(encodedMessage)];
    const char s[2] = "[";
    char *token = strtok(encodedMessage, s);
    char *ptr;
    int resStrLen = 0, strippedPos = 0, strippedLength = strlen(strStripped);
    while (token != NULL) {
        strippedPos = abs(strtol(token, &ptr, 10));
        if (strippedPos > strippedLength) {
            printf("Position of parsed char is outside bounds of compressed str: %d\n", strippedPos);
            return;
        }
        resStr[resStrLen++] = strStripped[strippedPos];
        // If char is marked as uppercase with '-' prefix..
        if ((token[0] == '-' ? 1 : 0)) {
            resStr[resStrLen - 1] = toupper(resStr[resStrLen - 1]);
        }

        if (ptr[strlen(ptr) - 1] != ']') {
            if (strlen(ptr) > 1 && ptr[strlen(ptr) - 2] != ']') {
                resStr[resStrLen++] = ptr[strlen(ptr) - 2];
            }
            resStr[resStrLen++] = ptr[strlen(ptr) - 1];
        }

        token = strtok(NULL, s);
    }
    resStr[resStrLen] = '\0';
    printf("%s\n", resStr);


    free(encodedMessage);
    free(strStripped);
}
示例#21
0
void testSpeed(const std::string& filepath, int N = 100)
{
	clock_t clk;
	// Test multiple json file
	auto f1 = getFileContent(filepath);

	if(f1.empty())
	{
		std::cout<<"Cannot find test file"<<std::endl;
		exit(0);
	}

	std::cout << "Test speed for file " << filepath << " (" << (f1.size() / 1024.0) << " KB) ... \n";
	clk = clock();
	for (int i = 0; i < N; ++i)
	{
		EJ::JSON j(f1.c_str());
	}
	std::cout << ">>> " << ((clock() - clk) / double(N)) << " ms\n";
}
示例#22
0
文件: ZipTest.cpp 项目: flo2k/CppZip
void ZipTest::test_addFile_Content_FromAString_WithPasswordProtection() {
    std::string contentAsString("this is a string");
    std::vector<unsigned char> content;
    content.insert(content.end(), contentAsString.begin(),
            contentAsString.end());
    bool expected = true;
    zip->open(tempFolder + "/" + zipFile, OpenFlags::CreateAndOverwrite, "secret");
    bool actual = zip->addFile(fileInsideZip, content);
    zip->close();

    CPPUNIT_ASSERT_EQUAL(expected, actual);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("count", 1, numFilesInZip(tempFolder + "/" + zipFile));
    CPPUNIT_ASSERT_EQUAL_MESSAGE("contains", true, containsFile(tempFolder + "/" + zipFile, fileInsideZip));

    std::vector<unsigned char> fileContent;
    fileContent = getFileContent(tempFolder + "/" + zipFile, fileInsideZip, "secret");
    std::string fileContentAsString(fileContent.begin(), fileContent.end());

    CPPUNIT_ASSERT_EQUAL_MESSAGE("file content", contentAsString, fileContentAsString);
}
示例#23
0
void TestImposter::onBattleServerConnected()
{
    BattleServerTest::onBattleServerConnected();

    Team t1;
    t1.importFromTxt(getFileContent("ditto.txt").trimmed());

    TeamBattle tb1, tb2;

    tb1 = TeamBattle(t1);
    tb2 = TeamBattle(t1);

    tb1.name = "Moogle";
    tb2.name = "Mystra";

    ChallengeInfo c;
    c.rated = true;

    analyzer->startBattle(1, BattlePlayer(tb1.name, 1), BattlePlayer(tb2.name, 2), c, tb1, tb2);
}
示例#24
0
int main(int argc, char *argv[])
{
	QCoreApplication a(argc, argv);
	QString scret="Little-Star", mac, license;
	license = getFileContent();
	std::cout <<"license: " <<  license.toUtf8().data() <<"\n";

	foreach(QNetworkInterface netInterface, QNetworkInterface::allInterfaces())
    {
		mac = netInterface.hardwareAddress();
		std::cout <<"mac: " <<  mac.toUtf8().data() <<"\n";
		QByteArray ba;  
		ba = QCryptographicHash::hash ( (scret+mac).toAscii(), QCryptographicHash::Md5 );  
		QString md5;
		md5.append(ba.toHex());  
		if(md5 == license) 
		{
			std::cout <<"matched!" <<"\n";
			break;
		}
		
    }
示例#25
0
char *getCompressedKey(const char *filename) {
    char *buffer = getFileContent(filename);
    if (buffer == NULL) {
        return NULL;
    }

    char *compressedStr = malloc(sizeof(char) * strlen(buffer));
    if (compressedStr == NULL) {
        perror("Unable to allocate memory");
        return NULL;
    }

    //char strStripped[strlen(buffer)];
    int i = 0, outputLength = 0;
    for (; i < strlen(buffer); i++) {
        if (isalpha(buffer[i])) {
            compressedStr[outputLength++] = tolower(buffer[i]);
        }
    }
    compressedStr[outputLength] = '\0';
    return compressedStr;
}
示例#26
0
文件: ZipTest.cpp 项目: flo2k/CppZip
void ZipTest::test_addFile_WithPasswordProtection() {
    bool expected = true;
    zip->open(tempFolder + "/" + zipFile, OpenFlags::CreateAndOverwrite, "secret");
    bool actual = zip->addFile("data/test/" + fileInsideZip , false);
    zip->close();

    CPPUNIT_ASSERT_EQUAL(expected, actual);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("count", 1, numFilesInZip(tempFolder + "/" + zipFile));
    CPPUNIT_ASSERT_EQUAL_MESSAGE("contains", true, containsFile(tempFolder + "/" + zipFile, fileInsideZip));

    std::vector<unsigned char> fileContent = getFileContent(tempFolder + "/" + zipFile, fileInsideZip, "secret");
    std::string fileContentAsString(fileContent.begin(), fileContent.end());
    
    //TODO: normally a would test it with the \n at the end, but it seems,
    //        that on windows a carriage return (13) and a new line (10) is added instead
    //        of one simple \n
    //std::string contentAsString("a\n");
    //CPPUNIT_ASSERT_EQUAL_MESSAGE("file content", contentAsString, fileContentAsString);

    std::string contentAsString("this is a string");
    CPPUNIT_ASSERT_MESSAGE("file content", boost::algorithm::starts_with(fileContentAsString, contentAsString));
}
void FontSizeWidget::initWidget()
{
    setObjectName("FontSizeWidget");
    setStyleSheet(getFileContent(":/resources/qss/fontsizewidget.qss"));
    setFixedSize(86, 18);
    m_fontSizeEdit = new QLineEdit(this);
    m_fontSizeEdit->setObjectName("FontSizeEdit");
    m_fontSizeEdit->setFixedSize(LINE_EDIT_SIZE);

    m_fontSize = ConfigSettings::instance()->value("text", "fontsize").toInt();
    m_fontSizeEdit->setText(QString("%1").arg(m_fontSize));
    m_addSizeBtn = new QPushButton(this);
    m_addSizeBtn->setObjectName("AddSizeBtn");
    m_addSizeBtn->setFixedSize(BUTTON_SIZE);
    m_reduceSizeBtn = new QPushButton(this);
    m_reduceSizeBtn->setObjectName("ReduceSizeBtn");
    m_reduceSizeBtn->setFixedSize(BUTTON_SIZE);

    QHBoxLayout* layout = new QHBoxLayout;
    layout->setMargin(0);
    layout->setSpacing(0);
    layout->addSpacing(4);
    layout->addWidget(m_fontSizeEdit);
    layout->addSpacing(0);
    layout->addWidget( new Seperator(this));
    layout->addWidget(m_addSizeBtn);
    layout->addWidget( new Seperator(this));
    layout->addSpacing(0);
    layout->addWidget(m_reduceSizeBtn);
    layout->addStretch();
    setLayout(layout);

    connect(m_addSizeBtn, &QPushButton::clicked, [=]{
        adjustFontSize(true);
    });
    connect(m_reduceSizeBtn, &QPushButton::clicked, [=]{
        adjustFontSize(false);
    });
}
void testcheckIfErrorOccured()
{

    int errorCode = 0;
    char *jsonFullPath = getFullFileName("tests/jsons/googleOauth2Access_invalidGrand.json");
    char *fileContent = getFileContent(jsonFullPath, &errorCode);
    CU_ASSERT_EQUAL_FATAL(errorCode, 0);
    CU_ASSERT_PTR_NOT_NULL_FATAL(fileContent);

    json_settings settings;
    memset(&settings, 0, sizeof (json_settings));
    char error[256];

    json_value *value = json_parse_ex(&settings, fileContent, error);
    CU_ASSERT_PTR_NOT_NULL_FATAL(value);
    
    int return_value = checkIfErrorOccured(value);
    CU_ASSERT_NOT_EQUAL(return_value, 0);
    CU_ASSERT_EQUAL(return_value, INVALID_GRAND);

    json_value_free(value); 
    
}
示例#29
0
int createTask(TDA_Task* task, char* path) {
  char* content; int out = 0;
  char* value = malloc(255 * sizeof(char));
  out = getFileContent(path, &content);

  if (out == -1) {
    return 2; // Bad file
  }

  initializeTask(task);

  do {
    out = parse(&content, &value);
    if (out > -1) out = handleKey(task, &value, &content);
  } while (out > 0);

  content = '\0'; // Si no hago eso me tira error, porque?

  free(content);
  free(value);

  return out;
}
SmsObject* FileManipulator::parseSmsFromFile (QString& file)
{
	SmsObject *result = NULL;
	QString *aux = NULL;
	
	result = new SmsObject();
	
	ASSERT (result != NULL);
	
	if (result != NULL) {
		/*!eso por ahoar despues cambiarlo, osea parsear todos los datos
		 *del sms y agregarlos a la estructura
		*/
		aux = getFileContent (file);
		result->setMesg (*aux);
		delete aux;
		aux = new QString ("3516545682");
		result->setNumber(*aux);
		delete aux;
	}
	
	return result;
}