Right now I am displaying something like /home/binary/ in QText browser. Now I want the open the folder by clicking on this text. How to do that ? Thanks in advance
Here is my sample code. I am display the result
s
bool MainWindow::displayResult(multimap<string,
string> &resultMap, string &filePath)
{
multimap::iterator iter;
bool fileStatus = false;
int noOfLocFound = 0, forAppending = 0;
QString no;
noOfLocFound = resultMap.size();
if ( noOfLocFound != 0 )
ui->textBrowser->append( "<i>File found at <b>" + no.setNum (
noOfLocFound ) + " locations");
for ( forAppending = 0,iter = resultMap.begin(); iter !=
resultMap.end(); iter++,
forAppending++ )
{
string file = iter->first;
string dir = iter->second;
if ( forAppending == 0)
filePath.append(dir);
else
filePath.append(","+dir);
QString qdir = QString::fromStdString(dir);
cout << "Display";
ui->textBrowser->append( qdir );
fileStatus = true;
}
if ( fileStatus == false )
{
ui->textBrowser->append("File not
found");
return false;
}
return true;
}
By "open the folder", do you mean, open a file dialog for the user to select something inside of the given directory?
If so, you would probably want to connect your QTextBrowser's clicked signal to a slot that looked something like:
// connect events, in MyWindow constructor, or whereever...
connect(textbrowser, SIGNAL(mousePressEvent(QMouseEvent*)), this, SLOT(openFileDialog(QMouseEvent*)));
void MyWindow::openFileDialog(QMouseEvent* event) {
Q_UNUSED(event);
QStringList files = QFileDialog::getOpenFileNames(this, "Select a file...",
textbrowser.plainText());
// do something with the files here...
}
Related
for example, In MySQL the query like this:
select name from test_tab where id = 1 and name like 'test%';
I want to translate this query in mongodb by mongodb C driver, so I write the code like this, but all don't work(the searchDoc() function is okay.
string strName = "";
bson_t *cond = bson_new();
BSON_APPEND_INT32(cond, "id", 1);
if (strlen(name.c_str()) > 0)
{
strName = "/^" + name + "/";
bson_t *child;
child = bson_new();
bson_append_document_begin(cond, "name", -1, child);
BSON_APPEND_UTF8(child, "$regex", strName.c_str());
bson_append_document_end(cond, child);
}
mongoc_cursor_t *cursor(NULL);
int iRet = searchDoc("db", "test_tab", cond, cursor);
if (iRet < 0)
{
bson_destroy(cond);
mongoc_cursor_destroy(cursor);
return -1;
}
and
string strName = "";
bson_t *cond = bson_new();
BSON_APPEND_INT32(cond, "id", 1);
if (strlen(name.c_str()) > 0)
{
strName = "/^" + name + ".*/";
BSON_APPEND_REGEX(cond, "name", strName.c_str(), "i");
}
mongoc_cursor_t *cursor(NULL);
int iRet = searchDoc("db", "test_tab", cond, cursor);
if (iRet < 0)
{
bson_destroy(cond);
mongoc_cursor_destroy(cursor);
return -1;
}
How can I build the regex pattern to query record work okay?
Thank you
I seach this page: https://jira.mongodb.org/browse/CDRIVER-206,
there is a important tips: "You do not need to include the forward-slash when building a regex."
so I delete the forward-slash, my code
strName = "/^" + name + ".*/";
BSON_APPEND_REGEX(cond, "name", strName.c_str(), "i");
change to
strName = "/^" + name + ".*/";
BSON_APPEND_REGEX(cond, "name", strName.c_str(), "i");
It can work. My problem has been solved.
What's The NameSpace for ShapeFile Class ?
my language is silverlight in Esri Map:
<esri:GraphicsLayer ShowLegend="false" ID="ResultsGraphicsLayer" />
<esri:GraphicsLayer ShowLegend="false" ID="MyGraphicsLayer" />
<esri:GraphicsLayer ShowLegend="false" ID="MySelectionGraphicsLayer" MouseEnter="GraphicsLayer_MouseEnter" MouseLeave="GraphicsLayer_MouseLeave"/>
<esri:GraphicsLayer ShowLegend="false" ID="IdentifyIconGraphicsLayer"/>
</esri:Map>
in codebehind:
private void openFileDialog_Click( object sender, RoutedEventArgs e )
{
//Create the dialog allowing the user to select the ".shp" and the ".dbf" files
OpenFileDialog ofd = new OpenFileDialog();
ofd.Multiselect = true;
if( !( ofd.ShowDialog() ?? false ) )
return;
//Get the file info objects for the SHP and the DBF file selected by the user
FileInfo shapeFile = null;
FileInfo dbfFile = null;
foreach( FileInfo fi in ofd.Files )
{
if( fi.Extension.ToLower() == ".shp" )
{
shapeFile = fi;
}
if( fi.Extension.ToLower() == ".dbf" )
{
dbfFile = fi;
}
}
//Read the SHP and DBF files into the ShapeFileReader
ShapeFile shapeFileReader = new ShapeFile();
if( shapeFile != null && dbfFile != null )
{
shapeFileReader.Read( shapeFile, dbfFile );
}
else
{
HtmlPage.Window.Alert( "Please select a SP and a DBF file to proceed." );
return;
}
//Add the shapes from the shapefile into a graphics layer named "shapefileGraphicsLayer"
//the greaphics layer should be present in the XAML or created earlier
GraphicsLayer graphicsLayer = MyMap.Layers[ "shapefileGraphicsLayer" ] as GraphicsLayer;
foreach( ShapeFileRecord record in shapeFileReader.Records )
{
Graphic graphic = record.ToGraphic();
if( graphic != null )
graphicsLayer.Graphics.Add( graphic );
}
I want to open a dialog to search for a filepath, without already creating the File and only saving the pathfile in a textBox.
This is what I already got, but it creates a new file:
System::IO::Stream^ myStream;
SaveFileDialog^ saveFileDialog1 = gcnew SaveFileDialog;
saveFileDialog1->Filter = "txt files (*.txt)|*.txt";
saveFileDialog1->FilterIndex = 2;
saveFileDialog1->RestoreDirectory = true;
if ( saveFileDialog1->ShowDialog() == ::DialogResult::OK )
{
if ( (myStream = saveFileDialog1->OpenFile()) != nullptr )
{
textBox->Text = saveFileDialog1->FileName;
myStream->Close();
}
}
Calling OpenFile is what's creating the file. Don't do it.
System::IO::Stream^ myStream;
SaveFileDialog^ saveFileDialog1 = gcnew SaveFileDialog;
saveFileDialog1->Filter = "txt files (*.txt)|*.txt";
saveFileDialog1->FilterIndex = 2;
saveFileDialog1->RestoreDirectory = true;
if ( saveFileDialog1->ShowDialog() == ::DialogResult::OK )
{
textBox->Text = saveFileDialog1->FileName;
}
Sorry if this is a repeat, but I'm trying to figure out the implementation of SoRayPickAction in Open Inventor. I'm trying to implement it so that it will, when the mouse is clicked, select a particular node so then I can translate, rotate, etc. I have three nodes: desk, lamp, and frame (picture frame). However, I don't think that my code is at all right. I also have various methods such a MouseButtonCallback (which will check if the mouse is clicked and then use a navigator) and MouseMoveCallback (same idea). So here's the code that I have, but do you have any suggestions? Right now, well, it doesn't do anything.
SbViewportRegion viewport(400,300);
SoRayPickAction m(viewport);
m.setRay(SbVec3f(0.0,0.0,0.0), SbVec3f(0.0,0.0,-1.0));
m.apply(callback_node);
const SoPickedPoint *mpp = m.getPickedPoint();
if(mpp != NULL) {
std::cout << "test" << std::endl;
}
Might you also know of an action in OpenInventor that can "place" a node in the scene, i.e. place the lamp on top of the desk, frame on the wall, etc. Is it with paths? I don't even know what I'm looking for, unfortunately. Thanks so much for your help!!
Edit: How does this look?
SoSeparator *desk2;
SoSeparator *lamp2;
SoSeparator *pic_frame2;
SoSeparator *picked;
void MouseButtonCallback(void* data, SoEventCallback* node)
{
SoHandleEventAction* action = node->getAction();
const SoMouseButtonEvent* event = static_cast<const SoMouseButtonEvent*>(action- >getEvent());
Navigator* nav = static_cast<Navigator*>(data);
if (SoMouseButtonEvent::isButtonPressEvent(event, event->getButton()))
nav->OnMouseDown(event, action);
else
nav->OnMouseUp(event, action);
const SbViewportRegion & viewportRegion = action->getViewportRegion();
SoRayPickAction pickAction(viewportRegion);
SbVec2s mousePos = event->getPosition(viewportRegion);
pickAction.setPoint(mousePos);
pickAction.setPickAll(TRUE);
pickAction.setRadius(2.0F);
pickAction.setRay(SbVec3f(0.0,0.0,0.0), SbVec3f(0.0,0.0,-1.0));
pickAction.apply(node);
const SoPickedPoint *mpp = pickAction.getPickedPoint();
if(mpp != NULL) {
SoPath *path = mpp->getPath();
if(desk2 != NULL && path->containsNode(desk2))
{ //but this doesn't respond with cout when I try to test it :(
if (SoMouseButtonEvent::isButtonPressEvent(event, event->getButton()))
*picked = *desk2;
}
else if(lamp2 != NULL && path->containsNode(lamp2))
{
if (SoMouseButtonEvent::isButtonPressEvent(event, event->getButton()))
*picked = *lamp2;
}
else if(pic_frame2 != NULL && path->containsNode(pic_frame2))
{
if (SoMouseButtonEvent::isButtonPressEvent(event, event->getButton()))
*picked = *pic_frame2;
}
action->setHandled();
}
void MouseMoveCallback(void* data, SoEventCallback* node)
{
SoHandleEventAction* action = node->getAction();
const SoLocation2Event* event = static_cast<const SoLocation2Event*>(action->getEvent());
Navigator* nav = static_cast<Navigator*>(data);
nav->OnMouseMove(event, action);
const SbViewportRegion & viewportRegion = action->getViewportRegion();
SoRayPickAction pickAction(viewportRegion);
SbVec2s mousePos = event->getPosition(viewportRegion);
pickAction.setPoint(mousePos);
pickAction.setPickAll(TRUE);
pickAction.setRadius(2.0F);
pickAction.setRay(SbVec3f(0.0,0.0,0.0), SbVec3f(0.0,0.0,-1.0));
pickAction.apply(node);
const SoPickedPoint *mpp = pickAction.getPickedPoint();
if(mpp != NULL) {
SoPath *path = mpp->getPath();
if(desk2 != NULL && path->containsNode(desk2))
{
*picked = *desk2; //can't remember how to set pointers, will figure that out
}
else if(lamp2 != NULL && path->containsNode(lamp2))
{
*picked = *lamp2;
}
else if(pic_frame2 != NULL && path->containsNode(pic_frame2))
{
*picked = *pic_frame2;
}
}
action->setHandled();
}
(part of main method)
//desk
SoTransform *desk_transform = new SoTransform;
desk_transform->translation.setValue(SbVec3f(380,340,330));
SoSeparator* desk2 = new SoSeparator();
desk2->addChild(desk_transform);
desk2->addChild(desk);
root->addChild(desk2);
SoTransformerManip* picked_transform = new SoTransformerManip();
picked_transform->translation.setValue(SbVec3f(200,340,330));
SoSeparator* pick2 = new SoSeparator();
pick2->addChild(picked_transform);
pick2->addChild(picked);
root->addChild(pick2);
std::auto_ptr<btCollisionShape> picked_shape(new btBoxShape(btVector3(10.0f, 10.0f, 10.0f)));
CollisionEngine* picked_collision = new CollisionEngine(collision_world.get(), picked_shape.get());
picked_collision->translation_in.connectFrom(&picked_transform->translation);
picked_collision->rotation_in.connectFrom(&picked_transform->rotation);
picked_transform->translation.connectFrom(&picked_collision->translation_out);
You have the picked point. You then get an SoPath as you guessed. Then see if the path contains a node you want to do something with.
SbViewportRegion viewport(400,300);
SoRayPickAction m(viewport);
m.setRay(SbVec3f(0.0,0.0,0.0), SbVec3f(0.0,0.0,-1.0));
m.apply(callback_node);
const SoPickedPoint *mpp = m.getPickedPoint();
if(mpp != NULL) {
std::cout << "test" << std::endl;
SoPath * path = pickedPoint->getPath();
if (deskSeparator != NULL && path->containsNode(deskSeparator)
{
}
else if (lampSeparator != NULL && path->containsNode(lampSeparator)
{
}
else if (radomeSeparator != NULL && path->containsNode(radomeSeparator)
{
if ( SoMouseButtonEvent::isButtonPressEvent( event, SoMouseButtonEvent::BUTTON2 )
|| ( SoMouseButtonEvent::isButtonPressEvent( event, SoMouseButtonEvent::BUTTON1 ) && event->wasShiftDown() ) )
{
modelPointMoving = true;
const SoDetail * detail = modelPickedPoint->getDetail( 0 );
int face = -1;
if ( detail && detail->isOfType( SoFaceDetail::getClassTypeId() ) )
{
const SoFaceDetail * faceDetail = static_cast<const SoFaceDetail *>( detail );
face = faceDetail->getFaceIndex();
}
updateStatusBar( face, point.getValue(), normal.getValue() );
graphicModel.postNote( pickedPoint );
break;
}
else if ( SoMouseButtonEvent::isButtonPressEvent( event, SoMouseButtonEvent::BUTTON1 ) )
{
}
else if ( SoMouseButtonEvent::isButtonReleaseEvent( event, SoMouseButtonEvent::BUTTON1 ) )
{
}
}
}
You'll eventually want to connect the pick ray to the mouse position sort of like this:
// Set an 2-pixel wide region around the pixel.
SbVec2s mousePosition = event->getPosition( viewportRegion );
pickAction.setPoint( mousePosition );
pickAction.setPickAll( TRUE );
pickAction.setRadius( 2.0F );
This is done before you .apply() the pick action of course.
I guess my code is a mixture of yours and mine but I think it should give you a start. Also, this is sitting inside a function to process mouse events:
void
RenderWindow::mouseEvent( void *, SoEventCallback * eventCallback )
{
const SoEvent *event = eventCallback->getEvent();
if ( ! event )
{
qDebug() << " ** Error in mousePressCallback: Event not found.";
return;
}
//SoType eventType = event->getTypeId();
//SbName eventTypeName = eventType.getName();
//const char * eventTypeString = eventTypeName.getString();
SoHandleEventAction * action = eventCallback->getAction();
const SbViewportRegion & viewportRegion = action->getViewportRegion();
SoRayPickAction pickAction( viewportRegion );
Up in main or a setup routine I register the mouse event (for both click action and location (moving the mouse over the viewport):
// Add a mouse event callback to catch mouse button presses.
SoEventCallback * mouseEventCallback = new SoEventCallback();
mouseEventCallback->setName( "MOUSE_EVENT_CALLBACK" );
mouseEventCallback->addEventCallback( SoMouseButtonEvent::getClassTypeId(), &::mouseEvent, static_cast<void *>( this ) );
// Add a mouse event callback to catch mouse motion.
mouseEventCallback->addEventCallback( SoLocation2Event::getClassTypeId(), &::mouseEvent, static_cast<void *>( this ) );
rootSeparator->addChild( mouseEventCallback );
Now that I look at it I wrote the chunks in reverse order ;-). Sorry.
Good Luck
I would like to know how to retrieve the list of users that are logged onto a Remote machine. I can do it with qwinsta /server:xxxx, but would like to do it in C#.
check out wmi in .net under system.management.
something like:
ConnectionOptions conn = new ConnectionOptions();
conn.Authority = "ntdlmdomain:NAMEOFDOMAIN";
conn.Username = "";
conn.Password = "";
ManagementScope ms = new ManagementScope(#"\\remotecomputer\root\cimv2", conn);
ms.Connect();
ObjectQuery qry = new ObjectQuery("select * from Win32_ComputerSystem");
ManagementObjectSearcher search = new ManagementObjectSearcher(ms, qry);
ManagementObjectCollection return = search.Get();
foreach (ManagementObject rec in return)
{
Console.WriteLine("Logged in user: " + rec["UserName"].ToString());
}
You may not need the ConnectionOptions...
I ended up using the qwinsta /server:server1 command from C# -- it was much easier
thanks Ken
All this checks all 8 servers at the same time -- I put the result in sql server
but you can do what ever you want
query_citrix.bat script
cd C:.......\bin\citrix_boxes
qwinsta -server:servername or ip > servername.txt
string sAppCitrixPath = Application.StartupPath.ToString() + "\\citrix_boxes\\";
//Run Script for current citrix boxes
Process proc = new Process();
ProcessStartInfo si = new ProcessStartInfo();
si.FileName = sAppCitrixPath + "query_citrix.bat";
proc.StartInfo = si;
proc.Start();
proc.WaitForExit();
int exitCode = proc.ExitCode;
proc.Close();
if (exitCode == 0)
{
//Execute update who is on the Citrix_Boxes Currently
DirectoryInfo dic = new DirectoryInfo(sAppCitrixPath);
FileInfo[] fic = dic.GetFiles("*.txt");
for (int i = 0; i < fic.Length; i++)
{
ParseQWinStaServerFile(fic[i].FullName.ToString(), fic[i].Name.ToString().ToUpper().Replace(".TXT",""));
File.Delete(fic[i].FullName.ToString());
}
}
private void ParseQWinStaServerFile(string sLocation,string sServer)
{
using (StreamReader sr = File.OpenText(sLocation))
{
string sRecord = String.Empty;
char[] cSep = new char[] {' '};
bool bFirst = true;
while ((sRecord = sr.ReadLine()) != null)
{
if (bFirst == false)
{
string[] items = sRecord.Split(cSep, StringSplitOptions.RemoveEmptyEntries);
//Make sure all columns are present on the split for valid records
if (sRecord.Substring(19, 1) != " ") // check position of user id to see if it's their
{
//Send the user id and server name where you want to.
//here is your user
id = items[1].ToString().ToLower().Trim()
//here is your server
};
}
else
{
bFirst = false;
}
}
}
}