Open in KolourPaint or another associated application #50

Manually merged
deloptes merged 1 commits from feat/open_in_kolourpaint into master 1 year ago
Collaborator

Signed-off-by: Emanoil Kotsev deloptes@gmail.com

Signed-off-by: Emanoil Kotsev <deloptes@gmail.com>
deloptes added 1 commit 1 year ago
f2ac34e605
Open in KolourPaint
deloptes changed title from Open in KolourPaint to WIP: Open in KolourPaint 1 year ago
Poster
Collaborator

This is a handy function if one wants to highlight or edit a screenshot before doing something else with it.

However, I need a bit of help to finalize this PR.

How can I pass the content of the buffer from ksnapshot to kolourpaint automatically?
ATM, I can CTRL+V after kolourpaint opens.

Also an idea around 383 - check or not check if kolourpaint is running

This is a handy function if one wants to highlight or edit a screenshot before doing something else with it. However, I need a bit of help to finalize this PR. How can I pass the content of the buffer from ksnapshot to kolourpaint automatically? ATM, I can CTRL+V after kolourpaint opens. Also an idea around 383 - check or not check if kolourpaint is running
blu.256 commented 1 year ago
Collaborator

You could use a KTempFile to store buffer data and pass that to KolourPaint.

You could use a KTempFile to store buffer data and pass that to KolourPaint.
blu.256 commented 1 year ago
Collaborator

It would be nice to offer other options along Kolourpaint, such as GIMP. Also, hardcoding paths is bad. Better use something like TDETrader

It would be nice to offer other options along Kolourpaint, such as GIMP. Also, hardcoding paths is bad. Better use something like TDETrader
Poster
Collaborator

It would be nice to offer other options along Kolourpaint, such as GIMP. Also, hardcoding paths is bad. Better use something like TDETrader

Thank you for the ideas.

I remember a saying - you give it the finger, it bites the hand.

What is TDETrader?

> It would be nice to offer other options along Kolourpaint, such as GIMP. Also, hardcoding paths is bad. Better use something like TDETrader Thank you for the ideas. I remember a saying - you give it the finger, it bites the hand. What is TDETrader?
blu.256 commented 1 year ago
Collaborator

TDETrader is part of TDEIO. In short, it allows you to dynamically query which applications support a given file type. If you want I can help you implement it. I'll test the PR shortly.

PS: Another reason we need TDETrader or something similar is so as to not hardcode paths. A user might have kolourpaint installed in a different prefix, such as /opt/tde, /usr or whatever (I know for sure Ray-V's SlackBuild scripts offer these prefixes as options for installing TDE).

TDETrader is part of TDEIO. In short, it allows you to dynamically query which applications support a given file type. If you want I can help you implement it. I'll test the PR shortly. PS: Another reason we need TDETrader or something similar is so as to not hardcode paths. A user might have kolourpaint installed in a different prefix, such as `/opt/tde`, `/usr` or whatever (I know for sure Ray-V's SlackBuild scripts offer these prefixes as options for installing TDE).
blu.256 commented 1 year ago
Collaborator

Also an idea around 383 - check or not check if kolourpaint is running

Could you please explain why we need this? Launching a new instance would be better in any case IMO since this is what the user expects.

> Also an idea around 383 - check or not check if kolourpaint is running Could you please explain why we need this? Launching a new instance would be better in any case IMO since this is what the user expects.
blu.256 added 1 commit 1 year ago
84fffa2d70
KSnapshot: Preload screenshot in KolourPaint
blu.256 commented 1 year ago
Collaborator

How can I pass the content of the buffer from ksnapshot to kolourpaint automatically?

I just pushed a commit that solves this problem by using a temporary file. When KolourPaint opens, it has loaded this file (seamlessly to the user) and allows editing. When the user saves the changes and closes the editor, the snapshot within KSnapshot gets updated, allowing the user to save/copy/print/drag the screenshot as usual.

> How can I pass the content of the buffer from ksnapshot to kolourpaint automatically? I just pushed a commit that solves this problem by using a temporary file. When KolourPaint opens, it has loaded this file (seamlessly to the user) and allows editing. When the user saves the changes and closes the editor, the snapshot within KSnapshot gets updated, allowing the user to save/copy/print/drag the screenshot as usual.
blu.256 force-pushed feat/open_in_kolourpaint from 84fffa2d70 to 3fc5fd6d26 1 year ago
blu.256 commented 1 year ago
Collaborator

Implemented KService/TDETrader functionality. Now we can be sure that KolourPaint is installed and provide options to open the snapshot in other applications associated with the according mimetype.

Implemented KService/TDETrader functionality. Now we can be sure that KolourPaint is installed and provide options to open the snapshot in other applications associated with the according mimetype.
blu.256 commented 1 year ago
Collaborator

@deloptes I'm waiting for your feedback. I hope that my work was helpful.

@deloptes I'm waiting for your feedback. I hope that my work was helpful.
Poster
Collaborator

Also an idea around 383 - check or not check if kolourpaint is running

Could you please explain why we need this? Launching a new instance would be better in any case IMO since this is what the user expects.

yes I also think so

> > Also an idea around 383 - check or not check if kolourpaint is running > > Could you please explain why we need this? Launching a new instance would be better in any case IMO since this is what the user expects. yes I also think so
Poster
Collaborator

How can I pass the content of the buffer from ksnapshot to kolourpaint automatically?

I just pushed a commit that solves this problem by using a temporary file. When KolourPaint opens, it has loaded this file (seamlessly to the user) and allows editing. When the user saves the changes and closes the editor, the snapshot within KSnapshot gets updated, allowing the user to save/copy/print/drag the screenshot as usual.

Thank you, it looks very good.

Now the "Open in KolourPaint" button is obsolete.

PS: I am sorry for answering that late - perhaps you had other expectations, but it is Sunday - a family day (and if it is not Sunday - it is work day).

> > How can I pass the content of the buffer from ksnapshot to kolourpaint automatically? > > I just pushed a commit that solves this problem by using a temporary file. When KolourPaint opens, it has loaded this file (seamlessly to the user) and allows editing. When the user saves the changes and closes the editor, the snapshot within KSnapshot gets updated, allowing the user to save/copy/print/drag the screenshot as usual. Thank you, it looks very good. Now the "Open in KolourPaint" button is obsolete. PS: I am sorry for answering that late - perhaps you had other expectations, but it is Sunday - a family day (and if it is not Sunday - it is work day).
blu.256 commented 1 year ago
Collaborator

I intentionally left the KolourPaint button as a quick shortcut when you need simple editing. IMO it is nice to have. And late reply is totally OK. Actually I was originally going to apologize for just giving bare pointers and not some working code.

I intentionally left the KolourPaint button as a quick shortcut when you need simple editing. IMO it is nice to have. And late reply is totally OK. Actually I was originally going to apologize for just giving bare pointers and not some working code.
deloptes reviewed 1 year ago
}
void KSnapshot::slotOpenWithKP() {
KService::Ptr kpaint = KService::serviceByDesktopName("kolourpaint");
Poster
Collaborator

Isn't it better to use #define KOLOURPAINT "kolourpaint"?
Someone was teaching me it is the preferred way.

Isn't it better to use #define KOLOURPAINT "kolourpaint"? Someone was teaching me it is the preferred way.
blu.256 commented 1 year ago
Collaborator

I think it would make sense in case we had a long string literal reused many times in the codebase and wanted a shorthand form for it, or if we defined it via CMake just before build time. I think that in this case it would be redundant, but I'm no C(++) guru.

Instead, we could use a #define for storing the default image output format (PNG) so that we could make it easier to change in case a change was .

I think it would make sense in case we had a long string literal reused many times in the codebase and wanted a shorthand form for it, or if we defined it via CMake just before build time. I think that in this case it would be redundant, but I'm no C(++) guru. Instead, we could use a #define for storing the default image output format (PNG) so that we could make it easier to change in case a change was .
SlavekB commented 1 year ago
Owner

I assume that if we were changing from kolourpaint to some other program, there would be other changes in the code – for example, the name of the kpaint variable. So it doesn't look too useful to use #define for this case.

But there is definitely an interesting note about the use of #define for the default image format. However, this is probably suitable for a separate change, not as part of this PR.

I assume that if we were changing from `kolourpaint` to some other program, there would be other changes in the code – for example, the name of the `kpaint` variable. So it doesn't look too useful to use `#define` for this case. But there is definitely an interesting note about the use of `#define` for the default image format. However, this is probably suitable for a separate change, not as part of this PR.
SlavekB marked this conversation as resolved
Poster
Collaborator

I intentionally left the KolourPaint button as a quick shortcut when you need simple editing. IMO it is nice to have. And late reply is totally OK. Actually I was originally going to apologize for just giving bare pointers and not some working code.

Hi Philippe,
thank you for the great work!
I am not the finest developer and there is too much about TDE I do not know.

My original use case was to be able to highlight some part of screenshot like this

image

And with your help it looks perfect. See my comment.

Also it is great that it cleans up the tmp file after closing.

So I would say, I remove the WIP and it can go.

> I intentionally left the KolourPaint button as a quick shortcut when you need simple editing. IMO it is nice to have. And late reply is totally OK. Actually I was originally going to apologize for just giving bare pointers and not some working code. Hi Philippe, thank you for the great work! I am not the finest developer and there is too much about TDE I do not know. My original use case was to be able to highlight some part of screenshot like this ![image](/attachments/56c3f5ab-617d-4a75-9459-209d5d534e5c) And with your help it looks perfect. See my comment. Also it is great that it cleans up the tmp file after closing. So I would say, I remove the WIP and it can go.
deloptes changed title from WIP: Open in KolourPaint to Open in KolourPaint 1 year ago
blu.256 commented 1 year ago
Collaborator

I just answered your comment. Once we resolve that little question you can freely merge this (of course, you might want to squash the commits into one first). Thank you for the initial work. It will be a great addition to KSnapshot!

I just answered your comment. Once we resolve that little question you can freely merge this (of course, you might want to squash the commits into one first). Thank you for the initial work. It will be a great addition to KSnapshot!
Poster
Collaborator

Thank you Philippe,
I am satisfied with the result and the comment by Slavek is also fine.
I will squash and push and leave it for merging.

BR

Thank you Philippe, I am satisfied with the result and the comment by Slavek is also fine. I will squash and push and leave it for merging. BR
deloptes force-pushed feat/open_in_kolourpaint from 3fc5fd6d26 to 418437b36d 1 year ago
SlavekB commented 1 year ago
Owner

It looks good. One small note: the git log message of your opening commit could also contain the prefix KSnaphot: .

It looks good. One small note: the git log message of your opening commit could also contain the prefix `KSnaphot: `.
SlavekB force-pushed feat/open_in_kolourpaint from 418437b36d to db379a2f50 1 year ago
SlavekB commented 1 year ago
Owner

Git log message updated, removed #include <tqbuffer.h> that is no longer needed. So we are ready to merge.

Git log message updated, removed `#include <tqbuffer.h>` that is no longer needed. So we are ready to merge.
SlavekB approved these changes 1 year ago
SlavekB left a comment
Owner

All looks good.

All looks good.
deloptes merged commit db379a2f50 into master manually 1 year ago
SlavekB deleted branch feat/open_in_kolourpaint 1 year ago
SlavekB added this to the R14.1.0 release milestone 1 year ago
MicheleC requested changes 1 year ago
MicheleC left a comment
Owner

Needs some fixes for potential SEGV. I will post steps to reproduce it in the Conversation section soon after.

Needs some fixes for potential SEGV. I will post steps to reproduce it in the Conversation section soon after.
}
}
static KTempFile *tmpFile = nullptr;
Owner

The user may capture multiple screenshots and open them in separate applications. Having a single tmpFile will lead to either SEGV (with the current code) or memory leak (if we protect against dereferencing nullptr).
We need a solution that keeps track of how many applications have been opened and which one is being closed. I will prepare a commit later or tomorrow, I have already an idea in mind.

The user may capture multiple screenshots and open them in separate applications. Having a single tmpFile will lead to either SEGV (with the current code) or memory leak (if we protect against dereferencing nullptr). We need a solution that keeps track of how many applications have been opened and which one is being closed. I will prepare a commit later or tomorrow, I have already an idea in mind.
}
void KSnapshot::slotExternalAppClosed() {
snapshot.load(tmpFile->name());
Owner

We should test for tmpFile being not a nullptr or it will lead to a SEGV. See comments that I will post soon on the Conversation page.

We should test for tmpFile being not a nullptr or it will lead to a SEGV. See comments that I will post soon on the Conversation page.
Owner

First of all, well done everyone for this. It is a very good improvement and something that was indeed missing by today's standard.

The current code can easily lead to SEGV. Steps to reproduce it:

  1. take a snapshop and open it in an application (say KolourPaint)
  2. without closing KSnapshot, open the same snapshot or a new one in Kolourpaint or another application.
  3. close the application launched at step 1 (or 2)
  4. close the other application --> KSnapshot crashes, because it is now dereferencing an invalid tmpFile.

I will create a fix and upload (either tonight or tomorrow)

First of all, well done everyone for this. It is a very good improvement and something that was indeed missing by today's standard. The current code can easily lead to SEGV. Steps to reproduce it: 1. take a snapshop and open it in an application (say KolourPaint) 2. without closing KSnapshot, open the same snapshot or a new one in Kolourpaint or another application. 3. close the application launched at step 1 (or 2) 4. close the other application --> KSnapshot crashes, because it is now dereferencing an invalid tmpFile. I will create a fix and upload (either tonight or tomorrow)
MicheleC changed title from Open in KolourPaint to Open in KolourPaint or another associated application 1 year ago
Owner

There is also another issue. Take a snapshot, open the file in KolourPaint and close KSnapshot. The temporary file is not getting deleted.

There is also another issue. Take a snapshot, open the file in KolourPaint and close KSnapshot. The temporary file is not getting deleted.
Owner

Please test PR #52, which proposes a solution for the issues raised above.

Please test PR #52, which proposes a solution for the issues raised above.
blu.256 referenced this issue from a commit 1 year ago

Reviewers

SlavekB approved these changes 1 year ago
MicheleC requested changes 1 year ago
The pull request has been manually merged as db379a2f50.
Sign in to join this conversation.
No Milestone
No Assignees
4 Participants
Notifications
Due Date

No due date set.

Dependencies

No dependencies set.

Reference: TDE/tdegraphics#50
Loading…
There is no content yet.