Пример #1
0
// Saves a settings file to (saveEntry). Returns true iff successful.
bool
ShortcutsWindow::_SaveKeySet(BEntry& saveEntry)
{
	BFile saveTo(&saveEntry, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
	if (saveTo.InitCheck() != B_NO_ERROR)
		return false;

	BMessage saveMsg;
	for (int i = 0; i < fColumnListView->CountItems(); i++) {
		BMessage next;
		if (((ShortcutsSpec*)fColumnListView->ItemAt(i))->Archive(&next) 
			== B_NO_ERROR)
			saveMsg.AddMessage("spec", &next);
		else
			printf("Error archiving ShortcutsSpec #%i!\n",i);
	}
	
	bool ret = (saveMsg.Flatten(&saveTo) == B_NO_ERROR);
	
	if (ret) {
		fKeySetModified = false;
		fSaveButton->SetEnabled(false);
	}

	return ret;
}
Пример #2
0
bool SettingsManager::save(const ArgumentParser * args) const {
	if(args != NULL) {
		QString altSettingsFileName = args->getValue("f");
		if(altSettingsFileName.length() > 0) {
			QByteArray fileNameBytes = altSettingsFileName.toLocal8Bit();

			printf("Saving settings to alternate file: %s\n", fileNameBytes.data());

			bool savedSettings = saveTo(altSettingsFileName);
			if(!savedSettings) {
				printf("Failed to save settings to alternate file: %s\n", fileNameBytes.data());
			}
			return savedSettings;
		}
	}

	return saveTo(defaultSettingsFileName);
}
Пример #3
0
void MainWindow::on_actionSave_As_triggered()
{
  QString tmpfilename = QFileDialog::getSaveFileName(
        this,
        tr("Save File"),
        "./",
        "Temperature Profile File (*.tpf)"
        );
  saveTo(tmpfilename);
}
Пример #4
0
bool OsmAnd::MapStylesPresets::saveTo(const QString& fileName) const
{
    QFile file(fileName);
    if(!file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text))
        return false;
    const auto success = saveTo(file);
    if(!success)
    {
        file.close();
        file.remove();
    }
    return success;
}
bool OsmAnd::FavoriteLocationsGpxCollection_P::saveTo(const QString& filename) const
{
	QFile file(filename);
	if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text))
		return false;

	QXmlStreamWriter writer(&file);
	writer.setAutoFormatting(true);
	const bool ok = saveTo(writer);
	file.close();

	return ok;
}
Пример #6
0
int SBookWidget::saveWithChoices(const char *title,QString &fn)
{
    QFileDialog fd(QString::null,0,this,title,true);

    fd.setMode(QFileDialog::AnyFile);
    fd.setCaption(title);
    fd.setSelection(QDir::currentDirPath());
    fd.setFilters((const char **)ofilters);

    if(fd.exec()==QDialog::Accepted){
	QString filter    = fd.selectedFilter();
	QString extension = filter.right(5);	  // get last 5 characters
	extension.truncate(4);			  // remove last ")"
	fn = fd.selectedFile();

	if(fn.right(4).lower().compare(extension)!=0){
	    fn += extension;			  // add the ending if not ther
	}

	if(access(fn.latin1(),0)==0){
	    if(QMessageBox::warning(0,"File Exists","The file "
				    + fn + " exists. Do you wish to overwrite it?",
				    "OK","Cancel",QString::null,1,1)==1){
		return -1;			  // aborted
	    }
	}

	if(filter.compare(ofilters[FILTER_XML])==0){
	    saveTo(fn);
	}
	if(filter.compare(ofilters[FILTER_SBOOK_ASCII])==0){
	    data.Export(fn.latin1(),FORMAT_SBOOK_ASCII);
	}
	if(filter.compare(ofilters[FILTER_PALM_CSV])==0){
	    data.Export(fn.latin1(),FORMAT_PALM_CSV);
	}
	if(filter.compare(ofilters[FILTER_CSV])==0){
	    data.Export(fn.latin1(),FORMAT_CSV);
	}
	if(filter.compare(ofilters[FILTER_TAB])==0){
	    data.Export(fn.latin1(),FORMAT_TAB);
	}
	if(filter.compare(ofilters[FILTER_IG])==0){
	    data.Export(fn.latin1(),FORMAT_IG);
	}
	return 0;				  // good save
    }
    return -1;					  // didn't save
}
Пример #7
0
EXPORT(sqInt) primitiveSynthesizeFrameIntoStartingAt(void) {
    float * aKlattFrame;
    short * buffer;
    sqInt bufferOop;
    sqInt rcvr;
    sqInt startIndex;
    sqInt oop;
    sqInt oop1;

	/* begin checkedFloatPtrOf: */
	oop = interpreterProxy->stackValue(2);
	interpreterProxy->success(interpreterProxy->isWords(oop));
	if (interpreterProxy->failed()) {
		aKlattFrame = 0;
		goto l1;
	}
	aKlattFrame = ((float *) (interpreterProxy->firstIndexableField(oop)));
l1:	/* end checkedFloatPtrOf: */;
	/* begin checkedShortPtrOf: */
	oop1 = (bufferOop = interpreterProxy->stackValue(1));
	interpreterProxy->success(interpreterProxy->isWords(oop1));
	if (interpreterProxy->failed()) {
		buffer = 0;
		goto l2;
	}
	buffer = ((short *) (interpreterProxy->firstIndexableField(oop1)));
l2:	/* end checkedShortPtrOf: */;
	startIndex = interpreterProxy->stackIntegerValue(0);
	if (interpreterProxy->failed()) {
		return null;
	}
	rcvr = interpreterProxy->stackObjectValue(3);
	if (!(loadFrom(rcvr))) {
		return null;
	}
	interpreterProxy->success(((interpreterProxy->stSizeOf(bufferOop)) * 2) >= samplesPerFrame);
	if (interpreterProxy->failed()) {
		return null;
	}
	synthesizeFrameintostartingAt(aKlattFrame, buffer, startIndex);
	if (!(saveTo(rcvr))) {
		return null;
	}
	interpreterProxy->pop(3);
	return null;
}
// Saves the application settings file to (saveEntry).  Because this is a
// non-essential file, errors are ignored when writing the settings.
void
ShortcutsWindow::_SaveWindowSettings(BEntry& saveEntry)
{
	BFile saveTo(&saveEntry, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
	if (saveTo.InitCheck() != B_OK)
		return;

	BMessage saveMsg;
	saveMsg.AddRect("window frame", Frame());

	for (int i = 0; i < fColumnListView->CountColumns(); i++) {
		CLVColumn* column = fColumnListView->ColumnAt(i);
		saveMsg.AddFloat("column width", column->Width());
	}

	saveMsg.Flatten(&saveTo);
}
Пример #9
0
int SBookWidget::menuSave(void)
{
    QString fn;

    if(strlen(data.filename)==0){		  // if no filename?
	if(saveWithChoices("Save As",fn)==0){		  // do a saveAs
	    setDirty(false);
	    return 0;
	}
	return -1;
    }
    if(dirty==false){				  // no sense to do the save
	return 0;				  // since we are not dirty
    }
    if(saveTo(data.filename)==0){		  // save to filename
	setDirty(false);			  // no longer dirty
	return 0;
    }
    return -1;
}
Пример #10
0
int main(int c,char **argv)
{
    QCoreApplication app(c,argv);
    if(app.arguments().size()<2) {
        qDebug() << app.arguments()[0] << " texturename";
        return 0;
    }
    QFile src_tex(app.arguments()[1]);
    if(src_tex.exists() && src_tex.open(QFile::ReadOnly)) {
        TexFileHdr hdr;
        src_tex.read((char *)&hdr,sizeof(TexFileHdr));
        if(0==memcmp(hdr.magic,"TX2",3))
        {
            qDebug() << "hdr.file_size" << hdr.file_size;
            qDebug() << "image size " << hdr.wdth << 'x'<<hdr.hght;
            qDebug() << "flags" << QString::number(hdr.flags,16);
            qDebug() << "fade" << hdr.fade[0]<< hdr.fade[1];
            qDebug() << "alpha" << QString::number(hdr.alpha,16);
            QString originalname=QString(src_tex.read(hdr.header_size-sizeof(TexFileHdr)));
            qDebug() << "Original name was:" << originalname;
            QFileInfo fi(originalname);
            QDir here;
            here.mkpath(fi.path());
            QFile unpacked(originalname);
            unpacked.open(QFile::WriteOnly);
            unpacked.write(src_tex.readAll());
            unpacked.close();
            CohTextureInfo info {
                hdr.file_size,
                hdr.wdth,
                hdr.hght,
                hdr.flags,
                {hdr.fade[0],hdr.fade[1]},
                hdr.alpha
            };
            qDebug() << saveTo(info);
        }
    }
    return 0;
}
void ServerInterface::getXMLDone()
{
    disconnect(m_reply, SIGNAL(finished()), this, SLOT(getXMLDone()));
    m_reply->deleteLater();
    if(checkError())
    {
        QString doctype = m_getDoc.first();
        m_getDoc.removeFirst();
        QFile saveTo(m_serverPath+doctype+".xml");
        saveTo.open(QIODevice::WriteOnly);
        saveTo.write(m_reply->readAll());
        saveTo.close();
        qDebug() << "got doc" << doctype;
        if(m_getDoc.isEmpty())
        {
            m_reply = NULL;
            emit checkoutDone(m_serverPath);
        }
        else
        {
            getXML();
        }
    }
}
Пример #12
0
void ofxWFrame::onSave(int & pressed){
	if(!pressed){
		saveTo(filename,xml_root);
	}
}
Пример #13
0
void
ShortcutsWindow::MessageReceived(BMessage* msg)
{
	switch(msg->what) {
		case OPEN_KEYSET: 
		case APPEND_KEYSET: 
			fLastOpenWasAppend = (msg->what == APPEND_KEYSET);
			if (fOpenPanel) 
				fOpenPanel->Show();
			else {
				BMessenger m(this);
				fOpenPanel = new BFilePanel(B_OPEN_PANEL, &m, NULL, 0, false);
				fOpenPanel->Show();
			}
			fOpenPanel->SetButtonLabel(B_DEFAULT_BUTTON, fLastOpenWasAppend ? 
				"Append" : "Open");
		break;

		case REVERT_KEYSET:
		{
			// Send a message to myself, to get me to reload the settings file
			fLastOpenWasAppend = false;
			BMessage reload(B_REFS_RECEIVED);
			entry_ref eref;
			_GetSettingsFile(&eref);
			reload.AddRef("refs", &eref);
			reload.AddString("startupRef", "yeah");
			PostMessage(&reload);
		}
		break;

		// Respond to drag-and-drop messages here
		case B_SIMPLE_DATA:
		{
			int i = 0;

			entry_ref ref;
			while (msg->FindRef("refs", i++, &ref) == B_NO_ERROR) {
				BEntry entry(&ref);
				if (entry.InitCheck() == B_NO_ERROR) {
					BPath path(&entry);
					
					if (path.InitCheck() == B_NO_ERROR) {
						// Add a new item with the given path.
						BString str(path.Path());
						DoStandardEscapes(str);
						_AddNewSpec(str.String());
					}
				}
			}
		}
		break;

		// Respond to FileRequester's messages here
		case B_REFS_RECEIVED:
		{
			// Find file ref
			entry_ref ref;
			bool isStartMsg = msg->HasString("startupRef");
			if (msg->FindRef("refs", &ref) == B_NO_ERROR) {
				// load the file into (fileMsg)
				BMessage fileMsg;
				{
					BFile file(&ref, B_READ_ONLY);
					if ((file.InitCheck() != B_NO_ERROR) 
						|| (fileMsg.Unflatten(&file) != B_NO_ERROR)) {
						if (isStartMsg) {
							// use this to save to anyway
							fLastSaved = BEntry(&ref);
							break;
						} else {
							(new BAlert(ERROR, 
								"Shortcuts was couldn't open your KeySet file!"
								, "Okay"))->Go(NULL);
							break;
						}
					}
				}
 
				if (fLastOpenWasAppend == false) {
					// Clear the menu...
					ShortcutsSpec * item;
					do {
						delete (item = ((ShortcutsSpec*)
							fColumnListView->RemoveItem(int32(0))));
					} while (item);
				}

				if (_LoadKeySet(fileMsg)) {
					if (isStartMsg) fLastSaved = BEntry(&ref);
					fSaveButton->SetEnabled(isStartMsg == false);

					// If we just loaded in the Shortcuts settings file, then 
					// no need to tell the user to save on exit.
					entry_ref eref;
					_GetSettingsFile(&eref);
					if (ref == eref) fKeySetModified = false;
				} else {
					(new BAlert(ERROR, 
						"Shortcuts was unable to parse your KeySet file!", 
						"Okay"))->Go(NULL);
					break;
				}
			}
		}
		break;

		// These messages come from the pop-up menu of the Applications column
		case SELECT_APPLICATION:
		{
			int csel = fColumnListView->CurrentSelection();
			if (csel >= 0) {
				entry_ref aref;
				if (msg->FindRef("refs", &aref) == B_NO_ERROR) {
					BEntry ent(&aref);
					if (ent.InitCheck() == B_NO_ERROR) {
						BPath path;
						if ((ent.GetPath(&path) == B_NO_ERROR) 
							&& (((ShortcutsSpec *)
							fColumnListView->ItemAt(csel))->
							ProcessColumnTextString(ShortcutsSpec::
							STRING_COLUMN_INDEX, path.Path()))) {
							
							fColumnListView->InvalidateItem(csel);
							_MarkKeySetModified();
						}
					}
				}
			}
		}
		break;

		case SAVE_KEYSET:
		{
			bool showSaveError = false;

			const char * name;
			entry_ref entry;
			if ((msg->FindString("name", &name) == B_NO_ERROR) 
				&& (msg->FindRef("directory", &entry) == B_NO_ERROR)) {
				BDirectory dir(&entry);
				BEntry saveTo(&dir, name, true);
				showSaveError = ((saveTo.InitCheck() != B_NO_ERROR) 
				|| (_SaveKeySet(saveTo) == false));
			} else if (fLastSaved.InitCheck() == B_NO_ERROR) {
				// We've saved this before, save over previous file.
				showSaveError = (_SaveKeySet(fLastSaved) == false);
			} else PostMessage(SAVE_KEYSET_AS); // open the save requester...

			if (showSaveError) {
				(new BAlert(ERROR, "Shortcuts wasn't able to save your keyset."
				, "Okay"))->Go(NULL);
			}
		}
		break;

		case SAVE_KEYSET_AS:
		{
			if (fSavePanel)
				fSavePanel->Show();
			else {
				BMessage msg(SAVE_KEYSET);
				BMessenger messenger(this);
				fSavePanel = new BFilePanel(B_SAVE_PANEL, &messenger, NULL, 0, 
					false, &msg);
				fSavePanel->Show();
			}
		}
		break;

		case B_ABOUT_REQUESTED:
			be_app_messenger.SendMessage(B_ABOUT_REQUESTED);
		break;

		case ADD_HOTKEY_ITEM:
			_AddNewSpec(NULL);
		break;

		case REMOVE_HOTKEY_ITEM:
		{
			int index = fColumnListView->CurrentSelection();
			if (index >= 0) {
				CLVListItem* item = (CLVListItem*) 
					fColumnListView->ItemAt(index);
				fColumnListView->RemoveItem(index);
				delete item;
				_MarkKeySetModified();

				// Rules for new selection: If there is an item at (index),
				// select it. Otherwise, if there is an item at (index-1), 
				// select it. Otherwise, select nothing.
				int num = fColumnListView->CountItems();
				if (num > 0) {
					if (index < num)
						fColumnListView->Select(index);
					else {
						if (index > 0)
							index--;
						if (index < num) 
							fColumnListView->Select(index);
					}
				}
			}
		}
		break;

		// Received when the user clicks on the ColumnListView
		case HOTKEY_ITEM_SELECTED:
		{
			int32 index = -1;
			msg->FindInt32("index", &index);
			bool validItem = (index >= 0);
			fRemoveButton->SetEnabled(validItem);
		}
		break;

		// Received when an entry is to be modified in response to GUI activity
		case HOTKEY_ITEM_MODIFIED:
		{
			int32 row, column;

			if ((msg->FindInt32("row", &row) == B_NO_ERROR) 
				&& (msg->FindInt32("column", &column) == B_NO_ERROR)) {
				int32 key;
				const char* bytes;

				if (row >= 0) {
					ShortcutsSpec* item = (ShortcutsSpec*)
						fColumnListView->ItemAt(row);
					bool repaintNeeded = false; // default

					if (msg->HasInt32("mouseClick")) {
						repaintNeeded = item->ProcessColumnMouseClick(column);
					} else if ((msg->FindString("bytes", &bytes) == B_NO_ERROR)
						&& (msg->FindInt32("key", &key) == B_NO_ERROR)) {
						repaintNeeded = item->ProcessColumnKeyStroke(column, 
							bytes, key);
					} else if (msg->FindInt32("unmappedkey", &key) == 
						B_NO_ERROR) {
						repaintNeeded = ((column == item->KEY_COLUMN_INDEX) 
							&& ((key > 0xFF) || (GetKeyName(key) != NULL)) 
							&& (item->ProcessColumnKeyStroke(column, NULL, 
							key)));
					} else if (msg->FindString("text", &bytes) == B_NO_ERROR) {
						if ((bytes[0] == '(')&&(bytes[1] == 'C')) {
							if (fSelectPanel)
								fSelectPanel->Show();
							else {
								BMessage msg(SELECT_APPLICATION);
								BMessenger m(this);
								fSelectPanel = new BFilePanel(B_OPEN_PANEL, &m,
									NULL, 0, false, &msg);
								fSelectPanel->Show();
							}
							fSelectPanel->SetButtonLabel(B_DEFAULT_BUTTON, 
								"Select");
						} else 
							repaintNeeded = item->ProcessColumnTextString(
								column, bytes);
					}
					
					if (repaintNeeded) {
						fColumnListView->InvalidateItem(row);
						_MarkKeySetModified();
					}
				}
			}
		}
		break;

		default:
			BWindow::MessageReceived(msg);
		break;
	}
}
Пример #14
0
/**
 * Saves the container to file using default <code>serializer</code>
 *
 * @param path a file to save data to
 * @throws IOException is thrown if there was a failure saving BDOC container. For example added
 *         document does not exist.
 * @throws BDocException is thrown if BDOC class is not correctly initialized.
 * @see save()
 */
void digidoc::BDoc::saveTo(std::string path) throw(IOException, BDocException)
{
    std::auto_ptr<ISerialize> serializer(new ZipSerialize(path));
    saveTo(serializer);
}
Пример #15
0
std::list<std::string> Lexer::split(const std::string& s) {
	std::list<std::string> ret;
	t = "";
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == ' ' || s[i] == '\t') {
			saveTo(ret);
			count++;
		} else if (s[i] == '\n' || s[i] == '\r'){
			saveTo(ret);
			count++;
		} else if (symbols.find(s[i]) != symbols.end()) {
			saveTo(ret);
			saveTo(std::string("") + s[i], ret);
		} else if ((s[i] >= 'a' && s[i] <= 'z') || (s[i] >= 'A' && s[i] <= 'Z')
				|| (s[i] >= '0' && s[i] <= '9' || s[i] == '_')) {
			t += s[i];
			//< <= <>
		} else if (s[i] == '<') {
			saveTo(ret);
			if (s[i + 1] == '>') {
				saveTo("<>", ret);
				i++;
			} else if (s[i + 1] == '=') {
				saveTo("<=", ret);
				i++;
			} else {
				saveTo("<", ret);
			}
			//> >=
		} else if (s[i] == '>') {
			saveTo(ret);
			if (s[i + 1] == '=') {
				saveTo(">=", ret);
				i++;
			} else {
				saveTo(">", ret);
			}
			//= ==
			//= = will be interpreted as two "="
		} else if (s[i] == '=') {
			saveTo(ret);
			if (s[i + 1] == '=') {
				saveTo("==", ret);
				i++;
			} else {
				saveTo("=", ret);
			}
			//&& ||
		} else if (s[i] == '&' || s[i] == '|') {
			saveTo(ret);
			if (s[i + 1] == s[i]) {
				saveTo(std::string("") + s[i] + s[i], ret);
				i++;
			} else {
				std::stringstream ss;
				ss << "Illegal Token at col " << count << " detected.";
				throw(SDBException(ss.str()));
			}
		} else if (s[i] == '!') {
			saveTo(ret);
			saveTo(std::string("") + s[i], ret);
		} else {
			std::stringstream ss;
			ss << "Illegal Token at col " << count << " detected.";
			throw(SDBException(ss.str()));
		}
	}
	saveTo(ret);
	return ret;
}
Пример #16
0
bool Model::saveTo(const QString &filePath)
{
    return !m_writer ? false : saveTo(filePath, *m_writer);
}
Пример #17
0
bool SettingsManager::saveTo(const QString & fileName) const {
	QByteArray fileNameBytes = fileName.toLocal8Bit();

	return saveTo(fileNameBytes.data());
}
Пример #18
0
bool SambaFile::slotApply()
{
  if (readonly) {
      kdDebug(FILESHARE_DEBUG) << "SambaFile::slotApply: readonly=true" << endl;
      return false;
  }      

  // If we have write access to the smb.conf
  // we simply save the values to it
  // if not we have to save the results in
  // a temporary file and copy it afterwards
  // over the smb.conf file with kdesu.
  if (QFileInfo(path).isWritable())
  {
    saveTo(path);
    changed = false;
    return true;
  }

  // Create a temporary smb.conf file
   delete _tempFile;
  _tempFile = new KTempFile();
  _tempFile->setAutoDelete(true);

  if (!saveTo(_tempFile->name())) {
    kdDebug(5009) << "SambaFile::slotApply: Could not save to temporary file" << endl; 
    delete _tempFile;
    _tempFile = 0;
    return false;
  }

  QFileInfo fi(path);
  KURL url(path);

  if (KURL(path).isLocalFile()) {
    KProcess proc;
    kdDebug(5009) << "SambaFile::slotApply: is local file!" << endl;
    
    QString suCommand=QString("cp %1 %2; rm %3")
              .arg(_tempFile->name())
              .arg(path)
              .arg(_tempFile->name());
    proc << "kdesu" << "-d" << suCommand;

    if (! proc.start(KProcess::Block)) {
        kdDebug(5009) << "SambaFile::slotApply: saving to " << path << " failed!" << endl;
        //KMessageBox::sorry(0,i18n("Saving the results to %1 failed.").arg(path));
        delete _tempFile;
        _tempFile = 0;
        return false;
    }        
    else {
        changed = false;
        delete _tempFile;
        _tempFile = 0;
        kdDebug(5009) << "SambaFile::slotApply: changes successfully saved!" << endl;
        return true;
    }        
  } else {
    kdDebug(5009) << "SambaFile::slotApply: is remote file!" << endl;
    _tempFile->setAutoDelete(true);
    KURL srcURL;
    srcURL.setPath( _tempFile->name() );

    KIO::FileCopyJob * job =  KIO::file_copy( srcURL, url, -1, true  );
    connect( job, SIGNAL( result( KIO::Job * ) ), 
             this, SLOT( slotSaveJobFinished ( KIO::Job * ) ) );
    return (job->error()==0);
  }

  return true;
}
Пример #19
0
void CIniFile::Save(void)
{
    saveTo(m_strFile.c_str());
}
Пример #20
0
void ofxBaseGui::saveToFile(string filename) {
	serializer->load(filename);
	saveTo(*serializer);
	serializer->save(filename);
}
Пример #21
0
void HtmlExtractor::save()
{
    saveTo(_path);
}