FET Forum

FET Support (English) => General Stuff => Topic started by: Andrés Chandía on July 19, 2010, 03:59:56 PM

Title: Same file modified by two users
Post by: Andrés Chandía on July 19, 2010, 03:59:56 PM
We have managed to put the fet files at a samba server, so the same files can be edited by a group of persons, the thing is that now we are looking for an option that allows you to see the file if somebody else is using it but without possibilities of editing it while in process by somebody else. Is there a way to do this?
Thanks for helping.
Title: Re: Same file modified by two users
Post by: Liviu Lalescu on July 20, 2010, 01:48:08 PM
Maybe you can do that: when a person opens the .fet file (first person), create a "name_of_file.locked". When the person closes the .fet file, remove that .locked file. Another person can open the .fet file, but cannot save if there exists a .locked file.

One problem: 1st user opens .fet file (F_Version_1), 2nd user opens .fet file, 1st user modifies, saves, closes, now 2nd user does a minor change (to the original file, F_Version_1), saves. The 1st user's modifications are lost. So maybe change above method, so that if second user opens file and .locked exists, he cannot save the file until he opens it again.

This can be implemented easily in FET, I can tell you where (in src/engine/rules.cpp, function read (line 5133) and function write (line 7019), maybe alternatively in src/interface/fetmainform.cpp, function on_fileOpenAction_activated (line 784) and function fileSaveAs (line 866)).

Edited to add: and function fileSave (fetmainform.cpp, line 1284).
Title: Re: Same file modified by two users
Post by: Andrés Chandía on July 20, 2010, 02:27:37 PM
Thanks again,
I will try it, to do it on windows installations, how should I proceed, I mean, should I do all of the changes once fet is installed or before,  and if it's before, how?
Title: Re: Same file modified by two users
Post by: Liviu Lalescu on July 20, 2010, 02:33:16 PM
QuoteThanks again,
I will try it, to do it on windows installations, how should I proceed, I mean, should I do all of the changes once fet is installed or before,  and if it's before, how?

I do not understand. Of course you need to change the sources of FET, compile and install (that is the order).

What do you mean by: "if it's before, how?"?
Title: Re: Same file modified by two users
Post by: Andrés Chandía on July 20, 2010, 02:43:45 PM
the thing is, in windows you download the zipped file, you expand it and you use it, no installation, that is the question related to.
Title: Re: Same file modified by two users
Post by: Liviu Lalescu on July 20, 2010, 02:52:56 PM
Quotethe thing is, in windows you download the zipped file, you expand it and you use it, no installation, that is the question related to.

Unpack fet-v.v.v.exe. You obtain the directory fet-v.v.v. In this directory, you can keep all the files, without fet.exe. You need to obtain a new fet.exe by compiling from sources, then overwrite your custom fet.exe over official fet.exe. Then, you have the whole directory and you can archive it, make it a self extracting archive, as you wish.

Or, you can get the sources (tar.bz2) FET, unpack, modify the sources as I told you, compile, eventually remove the src and tmp directories and files Makefile and fet.pro - then you obtain the same structure as above, containing the new fet.exe (so, no need to care about other details). Make it an archive, as above (the important and different from official archive is only fet.exe, which you obtain after compiling).

To compile, you need to get Qt and MinGW (or other C++ compiler), and follow the other advice in FET README. Modify the .cpp files, as I told you. Then compile. After compilation, you will get a new fet.exe file - this is the only file different from the official files.

Let me know if it is clear now.
Title: Re: Same file modified by two users
Post by: Andrés Chandía on July 20, 2010, 02:57:48 PM
Ok, so I can do the whole compiling process in linux and then install fet on windows?
Title: Re: Same file modified by two users
Post by: Liviu Lalescu on July 20, 2010, 03:04:38 PM
QuoteOk, so I can do the whole compiling process in linux and then install fet on windows?

Oh, no :-) . How can you run a GNU/Linux program under Windows?

You can modify FET sources under GNU/Linux, test them, then copy them under Windows and compile under Windows (using MinGW or MSVC, with Qt for Windows installed).

There may be other possibility: get mingw32 (with qt) libraries under GNU/Linux and do a cross-compile. I once managed to obtain the fet.exe like that, but it didn't run under Windows, it complained about missing .dll-s. Also, installation of cross-compile mingw32 under GNU/Linux is difficult, and you need to change some things, and compilation is also difficult.
Title: Re: Same file modified by two users
Post by: Andrés Chandía on July 20, 2010, 03:11:41 PM
Ok, got you.
Title: Re: Same file modified by two users
Post by: Andrés Chandía on September 10, 2010, 02:12:42 PM
I haven't done it jet, but now I'm comming back to this isue....

QuoteThis can be implemented easily in FET, I can tell you where (in src/engine/rules.cpp, function read (line 5133) and function write (line 7019), maybe alternatively in src/interface/fetmainform.cpp, function on_fileOpenAction_activated (line 784) and function fileSaveAs (line 866)).

Edited to add: and function fileSave (fetmainform.cpp, line 1284).

Sorry for my ignorance, but what should I write or change at all of those lines from the files you've mentioned?
Title: Re: Same file modified by two users
Post by: Andrés Chandía on September 11, 2010, 12:42:46 PM
Another stuff, I couldn't download the version you recommend of QT, because the link to older versions didn't work at qt.nokia page, do you have it, is it possible to share it?
Title: Re: Same file modified by two users
Post by: Andrés Chandía on September 13, 2010, 02:10:35 PM
Now is working the old stuff link, but anyway I still don't know how to proceed with the files, I mean what to edit (add, delete, change) at the mentioned lines.

Thanks
Title: Re: Same file modified by two users
Post by: Liviu Lalescu on September 13, 2010, 02:22:28 PM
Do you know C++ or have somebody who knows C++? It should be easy for such a person. And a bit of Qt (very little).

You can test if a file exists in Qt:


QFile::exists("file.ext");


You can create a file in Qt:


QFile file("file.ext");
file.open(QIODevice::WriteOnly);
file.close();


You can remove a file in Qt:


QFile::remove("file.ext");


Maybe you need to add this include:


#include <QFile>

Title: Re: Same file modified by two users
Post by: Andrés Chandía on September 15, 2010, 08:43:45 AM
So, you mean that is not a matter of just editing some stuff, are functions to be created (programmed)?
Sorry, but can you indicate what are you pointing to with the Qt commands you've sent me, I'm not a programmer, that's why is difficult for me to understand easily what you intend to make me be aware of.
Title: Re: Same file modified by two users
Post by: Liviu Lalescu on September 15, 2010, 10:33:13 AM
QuoteSo, you mean that is not a matter of just editing some stuff, are functions to be created (programmed)?
Sorry, but can you indicate what are you pointing to with the Qt commands you've sent me, I'm not a programmer, that's why is difficult for me to understand easily what you intend to make me be aware of.

I'll try to make you a file to use, but it is a bit difficult, as I am not at your place, to check the code in your environment, so it may not work.

I'll post here the modified file in a short time.
Title: Re: Same file modified by two users
Post by: Liviu Lalescu on September 15, 2010, 11:35:34 AM
I think I solved it (compile attached files).

There may still be bugs in my source, so please:

1) Compare by contents the official files and these files, and try to think if my code is correct.
2) Test much before relying to it as a safe function.
3) Don't be angry at me if I still forgot some situations and you get data loss. I'll try to fix the problems if you report them.
Title: Re: Same file modified by two users
Post by: Andrés Chandía on September 15, 2010, 02:26:28 PM
Thanks a lot Liviu, I will try the code, and check it, to send you a kind of inform of the situation, It will be run under windows XP.
Title: Re: Same file modified by two users
Post by: Andrés Chandía on September 20, 2010, 04:54:41 PM
Liviu, it was a complete success!!!!!

Thanks a lot SENSEI Liviu, I sent a memo to my boss letting her know that you've made the magic, for her to remember the pending stuff about donations.

Well now, some more little things, if it possible, instead letting people save the file with a different name, could it be so blocked that the user find himself forced to close the file and retry later. Something like "File in use, Retry Later!"

And thanks again.
Title: Re: Same file modified by two users
Post by: Liviu Lalescu on September 20, 2010, 05:47:21 PM
In file fetmainform.cpp, after line 899 ("{"), insert:


if(readOnly){
      QMessageBox::warning(this, tr(FET warning"), tr("File is in use by another user - cannot save"));
      return false;
}


and modify line 1354 (change the message "This file is in use..."). This is line 1354 before inserting the code above.

I hope I did no mistakes.
Title: Re: Same file modified by two users
Post by: Andrés Chandía on September 21, 2010, 09:31:06 AM
It gives me this error:


interface\fetmainform.cpp:901:100: warning: missing terminating " character
interface\fetmainform.cpp:901: error: missing terminating " character
interface\fetmainform.cpp: In member function 'bool FetMainForm::fileSaveAs()':
interface\fetmainform.cpp:901: error: 'FET' was not declared in this scope
mingw32-make[2]: *** [../tmp/fetmainform.o] Error 1
mingw32-make[2]: Leaving directory `C:/Programa-FET/src'
mingw32-make[1]: *** [release] Error 2
mingw32-make[1]: Leaving directory `C:/Programa-FET/src'
mingw32-make: *** [sub-src-make_default] Error 2


I've edited the file this way (the first line in this extract being 891:

           if(INPUT_FILENAME_XML!="" && !readOnly)
                 setWindowTitle(tr("FET - %1", "The title of the main window, %1 is the name of the current file").arg(INPUT_FILENAME_XML.right(INPUT_FILENAME_XML.length()-INPUT_FILENAME_XML.findRev("/")-1)));
           else if(INPUT_FILENAME_XML!="" && readOnly)
                 setWindowTitle(tr("FET - %1 [READ_ONLY]", "The title of the main window, %1 is the name of the current file").arg(INPUT_FILENAME_XML.right(INPUT_FILENAME_XML.length()-INPUT_FILENAME_XML.findRev("/")-1)));
     }
}

bool FetMainForm::fileSaveAs()
{
if(readOnly){
      QMessageBox::warning(this, tr(FET warning"), tr("File is in use by another user - cannot save"));
      return false;
}
     QString predefFileName=INPUT_FILENAME_XML;
     if(predefFileName=="")
           predefFileName=WORKING_DIRECTORY+FILE_SEP+"untitled.fet";
Title: Re: Same file modified by two users
Post by: Liviu Lalescu on September 21, 2010, 10:01:27 AM
Sorry, it should be:


if(readOnly){
      QMessageBox::warning(this, tr("FET warning"), tr("File is in use by another user - cannot save"));
      return false;
}


(add a " before FET warning text).
Title: Re: Same file modified by two users
Post by: Andrés Chandía on September 21, 2010, 11:16:09 AM
Ok, as long as I tested was OK, I will make it available for users now.

Thanks again Liviu