コード例 #1
0
ファイル: hxdir.cpp プロジェクト: muromec/qtopia-ezx
HXBOOL
CHXDirectory::SetTempPath(HXXHANDLE /* hpsHandle */, const char* szRelPath)
{
    // caller must specify a sub-directory
    if (szRelPath == NULL || szRelPath[0] == '\0') return FALSE;

    m_strPath.Empty();

    // try current working directory
    if (!SetCurrentDir() || !isWritable(m_strPath))
    {
	// go with /tmp
	m_strPath = "/tmp";
	if (!isWritable(m_strPath)) return FALSE;
    }
    
    // now append the sub-directory, separating if necessary
    if (m_strPath.Right(1) != OS_SEPARATOR_STRING && szRelPath[0] != OS_SEPARATOR_CHAR)
    {
	m_strPath += OS_SEPARATOR_STRING;
    }
    m_strPath += szRelPath;

    return TRUE;
}
コード例 #2
0
ファイル: filesystem.cpp プロジェクト: nemith/osquery
const std::string& osqueryHomeDirectory() {
  static std::string homedir;

  if (homedir.size() == 0) {
    // Try to get the caller's home directory
    boost::system::error_code ec;
    auto userdir = getHomeDirectory();
    if (userdir.is_initialized() && isWritable(*userdir).ok()) {
      auto osquery_dir = (fs::path(*userdir) / ".osquery");
      if (isWritable(osquery_dir) ||
          boost::filesystem::create_directories(osquery_dir, ec)) {
        homedir = osquery_dir.make_preferred().string();
        return homedir;
      }
    }

    // Fail over to a temporary directory (used for the shell).
    auto temp =
        fs::temp_directory_path(ec) / fs::unique_path("osquery%%%%%%%%", ec);
    boost::filesystem::create_directories(temp, ec);
    homedir = temp.make_preferred().string();
  }

  return homedir;
}
コード例 #3
0
ファイル: GfxBlockItem.cpp プロジェクト: wagenadl/eln
void GfxBlockItem::sizeToFit() {
  QRectF r = generousChildrenBounds();
  double minh = style().real("gfx-block-minh");
  if (r.height() < minh)
    r.setHeight(minh);

  double yref = data()->yref();
  double h = data()->height();

  bool mustemit = false;
  
  if (yref!=r.top()) {
    prepareGeometryChange();
    if (isWritable())
      data()->setYref(r.top());
    else
      data()->sneakilySetYref(r.top());
    mustemit = true;
  }
  if (h!=r.height()) {
    prepareGeometryChange();
    if (isWritable())
      data()->setHeight(r.height());
    else
      data()->sneakilySetHeight(r.height());        
    mustemit = true;
  }

  if (mustemit)
    emit heightChanged();
}
コード例 #4
0
// Copy data into sendRing
bool StreamReceiver::
write(SocketMessenger* m, Conduit* c)
{
    Synchronized<es::Monitor*> method(monitor);
    while (!isWritable())
    {
        if (!socket->getBlocking())
        {
            m->setErrorCode(EAGAIN);
            return false;
        }
        if (socket->getTimeout())
        {
            monitor->wait(socket->getTimeout());

            if (!isWritable())
            {
                m->setErrorCode(ETIMEDOUT);
                return false;
            }
            else
            {
                break;
            }
        }
        monitor->wait();
    }

    long len = socket->getSendBufferSize() - sendRing.getUsed();
    if (len < 0)
    {
        // XXX m->setErrorCode(XXX);
        return false;
    }

    if (m->getLength() < len)
    {
        len = m->getLength();
    }
    sendRing.write(m->fix(len), len);
    m->setPosition(m->getSize() - len);

    int size = 14 + 60 + 60 + mss;  // XXX Assume MAC, IPv4, TCP
    Handle<InetMessenger> seg = new InetMessenger(&InetReceiver::output, size, size);
    Handle<Address> addr;
    seg->setLocal(addr = m->getLocal());
    seg->setRemote(addr = m->getRemote());
    seg->setLocalPort(m->getLocalPort());
    seg->setRemotePort(m->getRemotePort());
    seg->setType(IPPROTO_TCP);
    seg->setFlag(m->getFlag());
    Visitor v(seg);
    conduit->accept(&v, conduit->getB());

    return false;
}
コード例 #5
0
ファイル: GfxBlockItem.cpp プロジェクト: wagenadl/eln
void GfxBlockItem::dragEnterEvent(QGraphicsSceneDragDropEvent *e) {
  QMimeData const *md = e->mimeData();
  qDebug() << "GfxBlockItem::dragEnterEvent: has image? " << md->hasImage()
	   << "hasurl?" << md->hasUrls()
	   << "hastext?" << md->hasText()
	   << "proposed" << e->proposedAction()
	   << "iswritable" << isWritable();
  if (isWritable() && (md->hasImage() || md->hasUrls() || md->hasText())) {
    e->setDropAction(Qt::CopyAction);
    setCursor(Cursors::crossCursor());
  } else {
    e->ignore();
  }
}
コード例 #6
0
int SequentialFile::initialize()
{
  if (memory->Size() == 0)
    memory->Resize(FIRST_RECORD_OFFSET);

  next_write_offset = (offset_t)memory->Size();
  next_write_offset = findNextAllocatedWord(next_write_offset);

  record_frame_t* raw = (record_frame_t*)offset2record(next_write_offset);

  if(next_write_offset == FIRST_RECORD_OFFSET) {  // this is a new empty file, everything is fine
    unsigned char* start = (unsigned char*)offset2record( 0 );

    if(isWritable())
      *start = SEQUENTIALFILE_DB_VERSION;

    return 0;
  }

  // find the first valid record
  // TODO: skip initial zeros after FIRST_RECORD_ADDRESS

  int lost_records = 0;
  while(raw > (record_frame_t*)FIRST_RECORD_ADDRESS) {
    if(assertValidRecordChain(raw))  // check whether at the current position could be a valid record
      break;

    raw--;
    lost_records = 1;
  }

  raw = raw + 1;

  next_write_offset = record2offset( (SequentialFile::Record*)raw );


  // find end, wipe out half-written records, write end of file marker
  // clean memory after first valid record

  if(isWritable()) {
    for( raw = raw; (char*)raw < memory->End(); raw++ ) {
      *raw = 0;
    }
  }
  rollback();    // remove any non-finalized transactions

  return lost_records;
}
コード例 #7
0
ファイル: SecureSocket.cpp プロジェクト: TotoxLAncien/synergy
ISocketMultiplexerJob*
SecureSocket::serviceAccept(ISocketMultiplexerJob* job,
				bool, bool write, bool error)
{
	Lock lock(&getMutex());

	int status = 0;
#ifdef SYSAPI_WIN32
	status = secureAccept(static_cast<int>(getSocket()->m_socket));
#elif SYSAPI_UNIX
	status = secureAccept(getSocket()->m_fd);
#endif
		// If status < 0, error happened
	if (status < 0) {
		return NULL;
	}

	// If status > 0, success
	if (status > 0) {
		sendEvent(m_events->forClientListener().accepted());
		return newJob();
	}

	// Retry case
	return new TSocketMultiplexerMethodJob<SecureSocket>(
			this, &SecureSocket::serviceAccept,
			getSocket(), isReadable(), isWritable());
}
コード例 #8
0
void SettingsDialog::accept()
{
    auto autoSave = QFileInfo(ui->autoSaveDirectory->text());
    if (!autoSave.exists())
    {
        QDir().mkpath(autoSave.absoluteFilePath());

    }
    if (!autoSave.exists() || !autoSave.isDir() || !autoSave.isWritable())
    {
        QMessageBox msg(this);
        msg.setIcon(QMessageBox::Warning);
        msg.setText("Can not access auto save directory");
        msg.setInformativeText(QString("Can not access auto save directory %1").arg(autoSave.absoluteFilePath()));
        msg.exec();
        return;
    }
    QSettings settings;
    settings.setValue("colorBackground", ui->background->currentIndex());
    settings.setValue("breakLines", ui->breakLines->isChecked());
    settings.setValue("maxMessages", ui->maxMessages->value());
    settings.setValue("autoSaveDirectory", ui->autoSaveDirectory->text());
    settings.setValue("timestampPrecision", ui->timestampFormat->currentIndex());
    QDialog::accept();
}
コード例 #9
0
// Add the specified file in the cache
bool GLC_CacheManager::addToCache(const QString& context, const GLC_3DRep& rep)
{
	Q_ASSERT(!rep.fileName().isEmpty());
	bool addedToCache= isWritable();
	if (addedToCache)
	{
		QFileInfo contextCacheInfo(m_Dir.absolutePath() + QDir::separator() + context);
		if (! contextCacheInfo.exists())
		{
			addedToCache= m_Dir.mkdir(context);
		}
		if (addedToCache)
		{
			QString repFileName= rep.fileName();
			if (glc::isArchiveString(repFileName))
			{
				repFileName= glc::archiveEntryFileName(repFileName);
			}
			else
			{
				repFileName= QFileInfo(repFileName).fileName();
			}
			const QString binaryFileName= contextCacheInfo.filePath() + QDir::separator() + repFileName;
			GLC_BSRep binariRep(binaryFileName, m_UseCompression);
			binariRep.setCompressionLevel(m_CompressionLevel);
			addedToCache= binariRep.save(rep);
		}
	}

	return addedToCache;
}
コード例 #10
0
bool QtIOCompressor::seek(qint64 pos)
{
    Q_D(QtIOCompressor);

    if(isWritable())
		return false;

	OpenMode mode = openMode();
	close();
    if(d->device->isOpen()) {
    	if(!d->device->reset())
    		return false;
    }
	if(!open(mode))
		return false;

	char buffer[0x10000];
	while(pos > 0) {
		qint64 s = read(buffer, std::min(pos, (qint64)sizeof(buffer)));
		if(s <= 0)
			return false;
		pos -= s;
	}

	return true;
}
コード例 #11
0
ファイル: kgpgfile.cpp プロジェクト: KDE/kmymoney
void KGPGFile::close()
{
  if (!isOpen()) {
    return;
  }

  if (!d->ctx)
    return;

  if (isWritable()) {
    d->m_data.seek(0, SEEK_SET);
    GpgME::Data dcipher(d->m_fileWrite->handle());
    d->m_lastError = d->ctx->encrypt(d->m_recipients, d->m_data, dcipher, GpgME::Context::AlwaysTrust).error();
    if (d->m_lastError.encodedError()) {
      setErrorString(QLatin1String("Failure while writing temporary file for file: '") + QLatin1String(d->m_lastError.asString()) + QLatin1String("'"));
    } else if (!d->m_fileWrite->commit()) {
      setErrorString("Failure while commiting file changes.");
    }
  }

  delete d->m_fileWrite;
  delete d->m_fileRead;
  d->m_fileWrite = 0;
  d->m_fileRead = 0;
  d->m_recipients.clear();
  setOpenMode(NotOpen);
}
コード例 #12
0
ファイル: QRListViewItem.C プロジェクト: alexjohn1362/rose
void QRListViewItem::paintCell( QPainter *p, const QColorGroup &cg,
                                int column, int width, int alignment)

{
    p->save();
    QColorGroup cgn(cg);

    if (isWritable(column)) {
        cgn.setColor(QColorGroup::Base, QColor(231,255,216));
    }

    if (((QRTreeBox *) listView()->parent())->isHighlight()) {
        if (column == 0 && m_node && ((QRTreeBox *) listView()->parent())->isNodeInCache(m_node)) {
            //cgn.setColor(QColorGroup::Base, QColor(231,255,216));
            cgn.setColor(QColorGroup::Base, QColor(216,239,202));
        }
    }

    Q3ListViewItem::paintCell(p,cgn,column,width,alignment);

    // Draw a box around the Cell
    int nheight = height() - 1;
    int nwidth = width - 1;
    p->setPen(cg.color(QColorGroup::Background));
    p->drawLine(0,nheight,nwidth,nheight);

    //p->lineTo(nwidth, 0);
    QPainterPath path;
    path.lineTo(nwidth, 0);
    p->drawPath(path);

    p->restore();

}
コード例 #13
0
ファイル: ftpfilesystem.cpp プロジェクト: peleccom/SpoKursach
QString FtpFileSystem::listDir(){
    QString fullPath = appendPath(mBaseDir, mCurDir);
    QDir dir(fullPath);
    if (!(dir.exists()))
        return NULL;

    dir.setSorting(QDir::Size | QDir::Reversed);
    QString buffer;
    QFileInfoList list = dir.entryInfoList();
    for (int i = 0; i < list.size(); ++i) {
        QFileInfo fileInfo = list.at(i);
        if (fileInfo.fileName()=="." || fileInfo.fileName() == "..")
            continue;
         QString dirLabel = fileInfo.isDir()?"d":"-";
         bool writable = isWritable(fileInfo.fileName());
         bool readable =  isReadable(fileInfo.fileName());
         QString sfileSize = fileInfo.isDir()?"512":QString::number(fileInfo.size());
         QDateTime dt = fileInfo.lastModified();
         QString lastModified = formatDate(dt);
//         qDebug() << fileInfo.fileName();
         buffer = buffer % QString("%1%5%6-r--r-- 1 root root %2 %3 %4\r\n").arg(dirLabel).arg(sfileSize).arg(lastModified).arg(fileInfo.fileName())
                .arg(readable?"r":"-").arg(writable?"w":"-");
    }
    return buffer;
}
コード例 #14
0
ファイル: qbuffer.cpp プロジェクト: Acidburn0zzz/doxygen
int QBuffer::writeBlock( const char *p, uint len )
{
#if defined(CHECK_NULL)
    if ( p == 0 && len != 0 )
	qWarning( "QBuffer::writeBlock: Null pointer error" );
#endif
#if defined(CHECK_STATE)
    if ( !isOpen() ) {				// buffer not open
	qWarning( "QBuffer::writeBlock: Buffer not open" );
	return -1;
    }
    if ( !isWritable() ) {			// writing not permitted
	qWarning( "QBuffer::writeBlock: Write operation not permitted" );
	return -1;
    }
#endif
    if ( (uint)ioIndex + len >= a_len ) {		// overflow
	uint new_len = a_len + a_inc*(((uint)ioIndex+len-a_len)/a_inc+1);
	if ( !a.resize( new_len ) ) {		// could not resize
#if defined(CHECK_NULL)
	    qWarning( "QBuffer::writeBlock: Memory allocation error" );
#endif
	    setStatus( IO_ResourceError );
	    return -1;
	}
	a_inc *= 2;				// double increment
	a_len = new_len;
	a.shd->len = (uint)ioIndex + len;
    }
    memcpy( a.data()+ioIndex, p, len );
    ioIndex += len;
    if ( a.shd->len < (uint)ioIndex )
	a.shd->len = (uint)ioIndex;		// fake (not alloc'd) length
    return len;
}
コード例 #15
0
ファイル: SCFileManager.cpp プロジェクト: moky/SnowCat
bool FileManager::move(const URL &sSourcePath, const URL &sTargetPath)
{
	if (!isExists(sSourcePath) || !isWritable(URL(sTargetPath).deleteLastPathComponent()))
	{
		SCError("cannot move file %s to %s", sSourcePath.c_str(), sTargetPath.c_str());
		return false;
	}
	
	if (rename(sSourcePath.c_str(), sTargetPath.c_str()) == 0)
	{
		return true;
	}
	SCLog("cannot rename %s to %s, try copying...", sSourcePath.c_str(), sTargetPath.c_str());
	
	// cannot rename, try copy
	if (!copy(sSourcePath, sTargetPath))
	{
		SCError("failed to copy file %s to %s", sSourcePath.c_str(), sTargetPath.c_str());
		return false;
	}
	
	if (!remove(sSourcePath))
	{
		SCWarning("cannot remove old file: %s", sSourcePath.c_str());
		return false;
	}
	
	return true;
}
コード例 #16
0
ファイル: qfile.cpp プロジェクト: kthxbyte/Qt1.45-Linaro
int QFile::putch( int ch )
{
#if defined(CHECK_STATE)
    if ( !isOpen() ) {				// file not open
	warning( "QFile::putch: File not open" );
	return EOF;
    }
    if ( !isWritable() ) {			// writing not permitted
	warning( "QFile::putch: Write operation not permitted" );
	return EOF;
    }
#endif
    if ( isRaw() ) {				// raw file (inefficient)
	char buf[1];
	buf[0] = ch;
	ch = writeBlock( buf, 1 ) == 1 ? ch : EOF;
    } else {					// buffered file
	if ( (ch = putc( ch, fh )) != EOF ) {
	    index++;
	    if ( index > length )		// update file length
		length = index;
	} else {
	    setStatus(IO_WriteError);
	}
    }
    return ch;
}
コード例 #17
0
ファイル: SecureSocket.cpp プロジェクト: RCB35/synergy
void
SecureSocket::secureAccept()
{
	setJob(new TSocketMultiplexerMethodJob<SecureSocket>(
			this, &SecureSocket::serviceAccept,
			getSocket(), isReadable(), isWritable()));
}
コード例 #18
0
ファイル: mfiledatastore.cpp プロジェクト: SamuelNevala/mlite
void MFileDataStore::fileChanged(const QString &fileName)
{
    Q_D(MFileDataStore);
    // sync the settings and add the path, for observing
    // the file even if it was deleted
    d->settings.sync();
    addPathsToWatcher(d->settings.fileName(), d->watcher);
    if (d->settings.fileName() == fileName && isWritable()) {
        // Check whether the values for existing keys have changed or
        // if keys have been deleted
        foreach(const QString & key, d->settingsSnapshot.keys()) {
            if ((d->settings.contains(key)
                    && d->settings.value(key) != d->settingsSnapshot.value(key))
                    || (!d->settings.contains(key))) {
                emit valueChanged(key, d->settings.value(key));
            }
        }
        // Check whether new keys have been added
        foreach(const QString & key, d->settings.allKeys()) {
            if (!d->settingsSnapshot.contains(key)) {
                emit valueChanged(key, d->settings.value(key));
            }
        }
        takeSnapshot();
    }
コード例 #19
0
ファイル: UmlArtifact.cpp プロジェクト: jeremysalwen/douml
bool UmlArtifact::set_roundtrip_expected()
{
    if ((stereotype() != "source") || cppSource().isEmpty())
        return TRUE;

    const Q3PtrVector<UmlClass> & cls = associatedClasses();

    if (cls.isEmpty()) {
        if ((name() == "main") && cppHeader().isEmpty())
            main_art = this;
        else
            return TRUE;
    }

    has_roundtrip_expected = TRUE;
    roundtrip_expected = TRUE;
    useless = TRUE;
    fully_updated = TRUE;
    ((UmlPackage *) parent()->parent())->get_package()->own(this);

    UmlClass ** v = cls.data();
    UmlClass ** vsup = v + cls.size();
    bool result = isWritable();

    for (; v != vsup; v += 1)
        result &= (*v)->set_roundtrip_expected();

    return result;
}
コード例 #20
0
ファイル: Packet.cpp プロジェクト: rabedik/hifi
bool Packet::reset() {
    if (isWritable()) {
        _payloadSize = 0;
    }

    return QIODevice::reset();
}
コード例 #21
0
ファイル: BinaryFile.cpp プロジェクト: kateyy/geohazardvis
bool BinaryFile::write(const void * data, size_t bytes)
{
    if (!isWritable())
    {
        return false;
    }

    if (bytes == 0u)
    {
        return true;
    }

    qint64 bytesRemaining = bytes;
    auto currentPtr = reinterpret_cast<const char *>(data);

    while (bytesRemaining)
    {
        auto bytesWritten = m_file->write(currentPtr, static_cast<qint64>(bytesRemaining));
        if (bytesWritten == 0)
        {
            break;
        }
        currentPtr += bytesWritten;
        bytesRemaining -= bytesWritten;
    }

    return bytesRemaining == 0;
}
コード例 #22
0
ファイル: mfiledatastore.cpp プロジェクト: SamuelNevala/mlite
bool MFileDataStore::createValue(const QString &key, const QVariant &value)
{
    Q_D(MFileDataStore);
    bool returnValue = false;
    // QSettings has some kind of a cache so we'll prevent any temporary writes
    // by checking if the data can be actually stored before doing anything
    if (isWritable()) {
        bool originalValueSet = d->settings.contains(key);
        QVariant originalValue = d->settings.value(key);
        d->settings.setValue(key, value);
        bool syncOk = doSync(d->settings, d->watcher);
        if (syncOk) {
            returnValue = true;
            // Emit valueChanged signal when value is changed or a new key is added
            if ((originalValueSet && originalValue != value)
                    || !originalValueSet) {
                d->settingsSnapshot[key] = value;
                emit valueChanged(key, value);
            }
        } else if (originalValueSet) {
            // if sync fails, make sure the value in memory is the original
            d->settings.setValue(key, originalValue);
        } else {
            d->settings.remove(key);
        }

    }
    return returnValue;
}
コード例 #23
0
void SequentialFile::erase( offset_t offset )
{
  ASSERT_TRUE(isWritable());

  Record* target = offset2record( offset );
  ASSERT_TRUE(target->isValid());
  offset_t end_offset = offset + target->GetRecordSize();

  char* target_end = (char*)target->getEndOfRecord();
  for (char* wiper = (char*)target; wiper < target_end; wiper++) {
    *wiper = 0;
  }

  // fix next_write_offset if it is the last record
  if (end_offset == next_write_offset) {
    iterator i = at(end_offset);
    i.GetPrevious();

    if (!i.IsValid()) {
      next_write_offset = 8;
    } else {
      next_write_offset = record2offset((Record*)i.GetRecord()->getEndOfRecord());
    }
  }
}
コード例 #24
0
ファイル: raw.hpp プロジェクト: pbl64k/icfpc2006
			Word &operator[](Word offset) {
#ifdef R_UM_OPT_ENFORCE_LOWLEV_VALIDITY
				assert(isWithinBounds(offset));
				assert(isWritable());
#endif
		
				return block_[offset];
			}
コード例 #25
0
/* {{{ MySQL_PreparedResultSetMetaData::isDefinitelyWritable -I- */
bool
MySQL_PreparedResultSetMetaData::isDefinitelyWritable(unsigned int columnIndex)
{
	CPP_ENTER("MySQL_PreparedResultSetMetaData::isDefinitelyWritable");
	CPP_INFO_FMT("this=%p", this);
	checkColumnIndex(columnIndex);
	return isWritable(columnIndex);
}
コード例 #26
0
ファイル: floatdataref.cpp プロジェクト: nbenford/ExtPlane
void FloatDataRef::setValue(float newValue) {
    if(!isWritable()) {
        INFO << "Tried to write read-only dataref" << name();
        return;
    }
    _value = newValue;
    XPLMSetDataf(ref(), _value);
}
コード例 #27
0
ファイル: kgpgfile.cpp プロジェクト: sajidji94/kmymoney2
Q_LONG KGPGFile::writeBlock(const char *data, Q_ULONG maxlen)
{
  if(!isOpen())
    return EOF;
  if(!isWritable())
    return EOF;

  return _writeBlock(data, maxlen);
}
コード例 #28
0
ファイル: intdataref.cpp プロジェクト: nbenford/ExtPlane
void IntDataRef::setValue(int newValue) {
    if(!isWritable()) {
        INFO << "Tried to write read-only dataref" << name();
        return;
    }
    DEBUG << name() << newValue;
    _value = newValue;
    XPLMSetDatai(ref(), _value);
}
コード例 #29
0
ファイル: Packet.cpp プロジェクト: rabedik/hifi
void Packet::setPayloadSize(qint64 payloadSize) {
    if (isWritable()) {
        Q_ASSERT(payloadSize <= _payloadCapacity);
        _payloadSize = payloadSize;
    } else {
        qDebug() << "You can not call setPayloadSize for a non-writeable Packet.";
        Q_ASSERT(false);
    }
}
コード例 #30
0
void SymmetricCipherStream::close()
{
    if (isWritable() && m_dataWritten) {
        writeBlock(true);
    }

    resetInternalState();

    LayeredStream::close();
}